Convert the string to XML in JS and read the object value instance.

Source: Internet
Author: User

To convert a string to an xml object on the java end, use incluenthelper. parseText (xmlReturn). getRootElement ();

In js, there are also ways to convert strings into xml objects. You can use the following functions:

Function createXml (str ){
If (document. all ){
Var xmlDom = new ActiveXObject ("Microsoft. XMLDOM ")
XmlDom. loadXML (str)
Return xmlDom
}
Else
Return new DOMParser (). parseFromString (str, "text/xml ")
} It is more convenient to read files on the js end.

Var xmlDoc = new ActiveXObject ("Msxml2.DOMDocument. 3.0 ");
XmlDoc. async = false;
XmlDoc. load ("file path"); xml operations are also very simple. If jdom or dom4j is used, the operation is quite convenient. Var domxml = createXml (Http. responseText );
Var code = domxml. getElementsByTagName ("code ");
If (code. item (0). text = "100 "){
Var parameter = domxml. getElementsByTagName ("parameter ");
Identifier = parameter. item (0). attributes. getNamedItem ("value"). value;
} The method for obtaining the node value and attribute value is different.

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.