PHP 5 and DOM XML

A

Anonymous

Guest
Hello,

I have been scouring the Internet looking for a tutorial on how to create new XML files using DOM and PHP5. I have found somethings, but have not been able to get them to work correctly. All I want to be able to do is create a simple xml file that i can save onto my computer that is created via PHP 5. For instance something that possibly looks like this:

Code:
  <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
- <echo_xml_setup_file>
- <Summary>
  <TotalRecords>1</TotalRecords> 
  <TotalAccepted>0</TotalAccepted> 
  <TotalRejected>0</TotalRejected> 
  <DocumentRejected>0</DocumentRejected> 
  <FileType>1</FileType> 
  </Summary>
  </echo_xml_setup_file>

Again I want to be able to create this from scratch, and not read it in from another file. Thanks any help is greatly appreciated.
 
I have read through that documentation a good number of times, but there isn't any good examples I can find on creating a new xml document. They give you code like:

Code:
<?php
$newdom = domxml_new_doc("1.0");
?>

But I dont know what to do with it afterwords. So that is pretty much where I am stuck. I am guessing I use the $newdom variable and append onto that, but like I said I do not know. So any help would give me a good start.

Thanks.
 
Since I don't have a PHP interpreter in front of my right now, I'll just have to guess, but glancing over the documentation it would seem that the create_element() method would be a good way to create an element, set_attribute() to set its attributes, and then you can append it to the DomDocument using its append_child() method.
 
Since I am using PHP 5 it is necessary to use just the DOM extension since PHP 5 replaced DOM XML with it. The documentation for this is located at: http://us2.php.net/manual/en/ref.dom.php.

Thanks
 
Actually I found out that using PHP 5 there is a new extension for DOM. To access the documentation for it go here: http://us2.php.net/manual/en/ref.dom.php This will get you and running with creating and using PHP for parsing and creating XML files.
 
jahnks said:
Actually I found out that using PHP 5 there is a new extension for DOM.

Actually, there are two. There's the one you mention and then there's SimpleXML. SimpleXML is also new and is generally regarded as being much easier to use. It wouldn't hurt to look into it.
 
Back
Top