RE: [PHP] How to build a XML DTD on the fly?
The code below lacks the part where the folling DTD attribute is created: !ATTLIST document id ID #IMPLIED How can I create the above DTD attribute in the code below? ?php // Creates an instance of the DOMImplementation class $oDomImp = new DOMImplementation; // Creates a DOMDocumentType instance $oDomDtd = $oDomImp-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: ?xml version=1.0 encoding=iso-8859-1 standalone=yes? !DOCTYPE document document id=123test/document TagName: 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, doesnt seem todo anything. :/ Jared -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to build a XML DTD on the fly?
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
RE: [PHP] How to build a XML DTD on the fly?
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, doesnt 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. setAttributeNS('http://www.w3.org/XML/1998/namespace', 'id', 'abc') doesnt work either, getElementById() still fails. Jared -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to build a XML DTD on the fly?
Jared Williams wrote: setAttributeNS('http://www.w3.org/XML/1998/namespace', 'id', 'abc') doesn’t work either, getElementById() still fails. It does work as long as you are using libxml2-2.6.22 Rob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php