Convert JavaScript strings to xml and use

Source: Internet
Author: User
Print? // Convert the string to xmlfunctiontoXmlDom (source) {varxmlDocnull; if (window. ActiveXObject) {varARR_ACTIVEX [& quot; MSXML4.DOMDocument & quot;, & quot; MSXML3.DOMDocument & quot;, & q

Print? // Convert string to xml
Function toXmlDom (source ){
Var xmlDoc = null;
If (window. ActiveXObject ){
Var ARR_ACTIVEX =
 
["MSXML4.DOMDocument", "MSXML3.DOMDocument", "MSXML2.DOMDocument", "MSXML. DOMDocument", "Microsoft. XmlDom"];
Var XmlDomflag = false;
For (var I = 0; I <ARR_ACTIVEX.length &&! XmlDomflag; I ++ ){
Try {
Var objXML = new ActiveXObject (ARR_ACTIVEX [I]);
XmlDoc = objXML;
XmlDomflag = true;
} Catch (e ){
}
}
If (xmlDoc ){
XmlDoc. async = false;
XmlDoc. loadXML (source );
}
} Else {
Var parser = new DOMParser ();
Var xmlDoc = parser. parseFromString (source, "text/xml ");
}
Return xmlDoc;
}

// Convert string to xml
Function toXmlDom (source ){
Var xmlDoc = null;
If (window. ActiveXObject ){
Var ARR_ACTIVEX =

["MSXML4.DOMDocument", "MSXML3.DOMDocument", "MSXML2.DOMDocument", "MSXML. DOMDocument", "Microsoft. XmlDom"];
Var XmlDomflag = false;
For (var I = 0; I <ARR_ACTIVEX.length &&! XmlDomflag; I ++ ){
Try {
Var objXML = new ActiveXObject (ARR_ACTIVEX [I]);
XmlDoc = objXML;
XmlDomflag = true;
} Catch (e ){
}
}
If (xmlDoc ){
XmlDoc. async = false;
XmlDoc. loadXML (source );
}
} Else {
Var parser = new DOMParser ();
Var xmlDoc = parser. parseFromString (source, "text/xml ");
}
Return xmlDoc;
}


 

[Javascript]
// Use
 
Function areaChart (data ){
Var s = toXmlDom (xml); // xml is a string
$ (S). find ("area"). each (// obtain the label of each area
Function (id, item ){
Var areaCode = $ (item). find ("area_code"). eq (0). text (); // obtain the area TAG content
Var num = $ (item). find ("area_all_num"). eq (0). text ();
Var name = $ (item). find ("area_name"). eq (0). text ();
Var title = name + "," + num;
$ ("#" + AreaCode + ""). attr ("title", title );

}
);

// Use

Function areaChart (data ){
Var s = toXmlDom (xml); // xml is a string
$ (S). find ("area"). each (// obtain the label of each area
Function (id, item ){
Var areaCode = $ (item). find ("area_code"). eq (0). text (); // obtain the area TAG content
Var num = $ (item). find ("area_all_num"). eq (0). text ();
Var name = $ (item). find ("area_name"). eq (0). text ();
Var title = name + "," + num;
$ ("#" + AreaCode + ""). attr ("title", title );

}
);

 

 

Related Article

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.