converting strings to XML objects on the Java side can use Documenthelper.parsetext (Xmlreturn). Getrootelement ();
In JS there is also a way to convert strings into XML objects, you can use the following functions
The following is a reference fragment:
Copy Code code as follows:
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 are reading a file on the JS side, it is more convenient
The following is a reference fragment:
Copy Code code as follows:
var xmldoc = new ActiveXObject ("msxml2.domdocument.3.0");
Xmldoc.async = false;
Xmldoc.load ("File path");
As for the operation of XML is also very simple, if you can use Jdom or dom4j, the operation is quite convenient.
The following is a reference fragment:
Copy Code code as follows:
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 value of the node and the value of the property are fetched differently.
The following method
Copy Code code as follows:
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;
}
Copy Code code as follows:
Use
function AreaChart (data) {
var s = toxmldom (XML);//xml is a string
$ (s). Find (' area '). each (///Get every area label
function (Id,item) {
var areacode=$ (item). FIND ("Area_code"). EQ (0). text ();//Get the contents of an area label
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);
}
);