Improvement on XML documents returned by WebService

Source: Internet
Author: User
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 );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.