Hello all:
Anyone know how to set an attribute for the root <?xml node in in PHP 5?
Thanks,
- John -
| SitePoint Sponsor |

Hello all:
Anyone know how to set an attribute for the root <?xml node in in PHP 5?
Thanks,
- John -

I assume your talking about the 'decleration', that only defines the version and character encoding, you can't add attributes to it. Its not a node at all. Your root node will be what directly follows that.

Sorry. Yes, I am talking abou the XML declaration. So there is no way to tell PHP to include a certain encoding?
Thanks,
- John -

I assume your talking about the 'decleration', that only defines the version and character encoding, you can't add attributes to it. Its not a node at all. Your root node will be what directly follows that.Code:<?xml version="1.0" encoding="ISO-8859-1"?>![]()

In code. I know how to write the XML, but when generating the DOM from PHP it creates the declaration on its own w/the bare minimum:
<?xml version="1.0" ?>
I need to add it after the fact.
- John -



When you create your DomDocument you can specify the version and the character encoding in the constructor.Originally Posted by ohnnyj
JTPHP Code:$xmldoc = new DomDocument("1.0", "iso-8859-1");





I was pondering on this myself with PHPversion4 a while back, although with the DOCTYPE as well as the XML declarationSorry. Yes, I am talking abou the XML declaration.
Didn't get very far though![]()



The same thing can be accomplished in PHP4. There are parameters to pass in to domxml_* functions for version and character encoding when you are creating the document and when you are saving it to file or printing to screen.Originally Posted by Widow Maker
JT

Awesome, just what I needed, thanks guys!
- John -





Seratonin,
Thought of that, but I couldn't get the DOCTYPE it's self working. Do you have an example ?



I think you have to use the doctype function which returns an instance of the DomDocumentType class and then manipulate it that way. I've never tried it and it is poorly documented.Originally Posted by Widow Maker
http://us4.php.net/manual/en/functio...nt-doctype.php
JT
Bookmarks