XMLDOM can well process XML documents, but there are considerable differences between browsers such as IE and Firefox. This kind of comprehensive processing method makes it compatible with various browsers
This class is based on xml dom and only processes incompatible parts of various browsers. It cannot be fully applied to XML processing. before using it, you must understand xml dom. For more information, see the network
Method:
- XML. load (url) loads XML files and returns XML objects.
- XML. loadXML (XMLString) loads XML strings and returns XML objects.
- XML. childNodes (node) gets a node subnode and returns an array of objects. // It mainly filters out the annoying empty nodes in Firefox.
- XML. xml (node) gets the formatted text of a node and returns string // IE. xml. This method is not available in FF.
- XML. text (node) gets a node value and returns a string // FF. This method is also unavailable.
- XML. selectSingleNode (node, xpath) uses xpath to obtain the first matching node under the node and return the node object. // each method has a uniform method to the DOM of IE.
- XML. selectNodes (node, xpath) uses XPath to retrieve all matching nodes under the node and return the node object set. // each method has a uniform method to the DOM of IE.
Example of linkage between provinces and municipalities <Script src = "jquery. js"> </script>
<Script src = "xml. js"> </script>
<Style type = "text/css">
Select {width: 150px}
</Style>
<Script type = "text/javascript">
<! --
$ (Function (){
Var xml = XML. load ("city1.xml ");
Var xmldoc=xml.doc umentElement; // root layer
Var nodes = XML. selectNodes (xmldoc, "// Item [@ pid = '0']"); // retrieves the xpath Node
For (var I = 0; I <nodes. length; I ++)
$ ("<Option/> "). val (nodes [I]. getattribute ("ID ")). text (nodes [I]. getattribute ("value ")). appendto ($ ("select [name = 'addr1']");
$ ("Select [name = 'addr1']"). Change (function (){
// Link the second layer
Select_change (this. Value, 'addr2 ');
$ ("Select [name = 'addr2']"). Change ();
});
$ ("Select [name = 'addr2']"). Change (function (){
// Link to Layer 3
Select_change (this. value, "addr3 ");
});
$ ("Select [name = 'addr1']"). Change ();
$ ("Select [name = 'addr2']"). Change ();
Function select_change (value, O ){
$ ("Select [name = '" + O + "']"). Empty ();
Var nodes = XML. selectNodes (xmldoc, "// Item [@ pid = '" + value + "']");
For (var I = 0; I <nodes. length; I ++)
$ ("<Option/> "). val (nodes [I]. getAttribute ("id ")). text (nodes [I]. getAttribute ("value ")). appendTo ($ ("select [name = '" + o + "']");
};
});
// -->
</Script>
</Head>
<Body>
<Select name = "addr1"> </select>
<Select name = "addr2"> </select>
<Select name = "addr3"> </select>
Download point here
Click here for demonstration