[PHP] Re: How to build a XML DTD on "the fly"?
My real problem is that I am building a XML tree and I want to use the getElementbyId method on the tree directly. It would be very nice if it is possible to do it without including a external dtd, since it takes some time to load every time. The page http://blog.bitflux.ch/wiki/GetElementById_Pitfalls have some information about my issue, but I have not found the path to go yet. I am using php5.05 on Win32. /Erik Rob wrote: Jared Williams wrote: There is no real standard for creating DTDs on the fly, and therefore libxml/DOM doesn't have any methods afaik. The one method DOMElement::setIDAttribute() should work I think, but whilst PHP has the method, doesn’t seem todo anything. :/ DocumentType nodes are read-only in DOM thus cannot be built on the fly. Also notice that not all components, such as ATTLIST, even have a node type. setIDAttribute - thats on the TODO list. Were some previous libxml issues to be resolved before that could be implemented (so it will be added, but require a minimum libxml2 version to work). Can always use xml:id attributes for that purpose for now though. Rob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: How to build a XML DTD on "the fly"?
I saw this example on http://blog.bitflux.ch/wiki/GetElementById_Pitfalls and thought that I could create the DTD in the XML file. $xml =' ]> '; $dom = new DomDocument(); $dom->loadXML($xml); print $dom->getElementById('myId')->nodeName; But apparently, that is not the case. /Erik James Benson wrote: Learn DTD and how it works first then you will know :-) A DTD is contained in an external file and not in XML, so you would create a DTD file then link it from the XML like so, Erik Franzén wrote: The code below lacks the part where the folling DTD attribute is created: How can I create the above DTD attribute in the code below? createDocumentType('document', null, null); // Creates a DOMDocument instance $oDom = $oDomImp->createDocument("", "", $oDomDtd); // Set other properties $oDom->encoding = 'iso-8859-1'; $oDom->standalone = true; // Create an empty element $oElement = $oDom->createElement('document', 'test'); $oElement->setAttribute('id', '123'); // Append the element $oDom->appendChild($oElement); // Retrieve and print the document echo $oDom->saveXML() . "\n"; echo "TagName: " . $oDom->getElementById('123')->tagName; ?> Now the code produces the following result: test TagName: Thanks /Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: How to build a XML DTD on "the fly"?
Learn DTD and how it works first then you will know :-) A DTD is contained in an external file and not in XML, so you would create a DTD file then link it from the XML like so, Erik Franzén wrote: The code below lacks the part where the folling DTD attribute is created: How can I create the above DTD attribute in the code below? createDocumentType('document', null, null); // Creates a DOMDocument instance $oDom = $oDomImp->createDocument("", "", $oDomDtd); // Set other properties $oDom->encoding = 'iso-8859-1'; $oDom->standalone = true; // Create an empty element $oElement = $oDom->createElement('document', 'test'); $oElement->setAttribute('id', '123'); // Append the element $oDom->appendChild($oElement); // Retrieve and print the document echo $oDom->saveXML() . "\n"; echo "TagName: " . $oDom->getElementById('123')->tagName; ?> Now the code produces the following result: test TagName: Thanks /Erik -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php