In DOMIT!, a DOM Document is represented by the DOMIT_Document class.
Below is an example of the cd collection XML string from the previous page being instantiated as a DOMIT_Document.
- First, the DOMIT_Document is created and assigned to the variable $cdCollection.
- Then, an XML string is passed to the parseXML method.
$cdCollectionString = "<cdlibrary><cd id=\"0001\">
<name>Robbie Fulks</name>
<title>Couples in Trouble</title></cd>
<cd id=\"0002\"><name>Richard Thompson</name>
<title>Mock Tudor</title></cd><cd id=\"0003\">
<name>Keller Williams</name>
<title>Laugh</title></cd></cdlibrary>";
$cdCollection =& new DOMIT_Document();
$success = $cdCollection->parseXML($cdCollectionString, true);
parseXML returns true if the parsing is successful.
Note that the second parameter to the parseXML method should be set to true if you wish to use the SAXY parser instead of the Expat browser.
You can query your document using the parsedBy method to find out which parser was used to generate the document.
$parserName = $cdCollection->parsedBy();
You can also use the loadXML method to load an XML string from a text file.
$cdCollection =& new DOMIT_Document();
$success = $cdCollection->loadXML("/xml/cdcollection.xml");
|