Improvement on WebService calling by post method written a few days ago. suddenly a problem occurs. When the XML document returned by WebService has multiple sub-nodes, there will be many Minus signs in innertext stored in IFRAME ...., in this way, when loading the innertext using the loadxml method... an error occurs. (The minus sign is automatically generated by the XML document, but it becomes a character in innertext. Imagine there are many such minus signs in the next XML string to be loaded, can it be a standard XML document? I don't know if you understand what I want to express...) Anyway, you just need to remove the minus sign ....
Function getxmlmsg ()
...{
Alert(xmlfile.doc ument. Body. innertext );
VaR str=xmlfile.doc ument. Body. innertext;
STR = Str. Split ("-"). Join (""); // remove the minus sign
Alert (STR );
VaR xmldoc = new activexobject ("Microsoft. xmldom ");
Xmldoc. async = "false ";
Xmldoc. loadxml (STR );
// Var msg.pdf xmldoc.doc umentelement. childnodes. Item (0). text;
// Alert (MSG );
// Alert (xmldoc. XML );
VaR MSG = xmldoc. childnodes [1]. childnodes [1]. childnodes [0]. childnodes [0]. text;
Alert (MSG );
}
Or adopt a more intelligent approach, because you only want the key part of the returned XML document. then we can extract the key part, create a new node, and put the extracted content into the new node to form a new XML document.
// Creat xmldom instance
Function createxmldom ()
...{
// Build a String Array
VaR arrsignatures = ["msxml2.domdocument. 5.0", "msxml2.domdocument. 4.0 ",
"Msxml2.domdocument. 3.0", "msxml2.domdocument ",
"Microsoft. xmldom"];
// Circle the array until creat the xmldom instence
For (VAR I = 0; I <arrsignatures. length; I ++ )...{
Try ...{
VaR oxmldom = new activexobject (arrsignatures [I]);
Return oxmldom;
} Catch (oerror )...{
// On error ignore
}
}
Throw new error ("You system have not MSXML ");
}
// Dom instance load XML format string, and Trans to xmldom instance
Function creatstrdom (STR, BSTR, estr)
...{
VaR Doc = createxmldom (); // creat the null xmldom
STR = Str. Split (""). Join (""); // Delete newline sign and enter sign
STR = Str. Split (""). Join (""); // Delete Space
STR = Str. Slice (Str. indexof (BSTR), str. indexof (estr); // intercept a part of the STR, capture the desired part
STR = "<root>" + STR + "</root>"; // Add the string root node, create a node, and add the intercepted part to this node.
Doc. async = false; // set async is false
Doc. loadxml (STR); // load the string to build to a xmldom instance (if wanna load a XML file, shocould use function "load ()" but "loadxml ([String]) "), import the New XML string, instead of the stuff in innertext.
Return Doc; // return Doc instance
}
Function getxml1 ()
...{
VaR str1 = xmlfile.doc ument. Body. innertext;
VaR tag = '<newdataset xmlns = ""> ';
Alert (str1 );
Str1 = str1.slice (str1.indexof ('<newdataset xmlns = "">') + tag. length, str1.indexof ("</newdataset>") // obtain <newdataset>... </newdataset>
Alert (str1 );
// Var xmldoc = creatstrdom (str1, '-<newdataset xmlns = "">', '</newdataset> ');
// Alert (xmldoc. XML );
}