You are here: Re: How to build a XML DTD on "the fly"? « PHP « IT news, forums, messages
Re: How to build a XML DTD on "the fly"?

Posted by Erik Franzιn on 10/27/45 11:32

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 ='<?xml version="1.0"?>
<!DOCTYPE foo [
<!ATTLIST bar
id ID #IMPLIED
>
]>
<foo>
<bar id="myId"/>
</foo>';
$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,
>
>
> <!DOCTYPE document SYSTEM "document.dtd">
>
>
>
>
>
> Erik FranzΓ©n wrote:
>
>> 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="123">test</document>
>>
>> TagName:
>>
>>
>> Thanks
>> /Erik
>
>

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация