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

Source: Internet
Author: User
You can convert a string to an XML Object in Java. Use Incluenthelper. parsetext (xmlreturn). getrootelement ();

In JS, there are also ways to convert strings into XML objects. You can use the following Function

The following is a reference clip:
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 ")
}

If you want to read File It is more convenient.

The following is a reference clip:
VaR xmldoc = new activexobject ("msxml2.domdocument. 3.0 ");
Xmldoc. async = false;
Xmldoc. Load ("file path ");

As for XML operations Simple If JDOM or dom4j is used, the operation is quite convenient.

The following is a reference clip:
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;
}

Obtain the node value and attribute value Method 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.