Help with creating an XML Document
| From: | Eric L. Sammons | Date: | Wed, 23 Jun 2004 14:18:19 +0000 |
| Subject: | Help with creating an XML Document | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-188873@lists.php.net to get a copy of this message | ||
Using PHP 4.3.2 I am trying to create an XML file that looks similar to the
following:
<?xml version="1.0" encoding="UTF-8"?>
<Server Name="pxtest01">
<Serical_Number>000000000</Serical_Number>
<Asset_Tag>00000</Asset_Tag>
<Model>DL380</Model>
<Location>8th Floor</Location>
<Cabinet>2</Cabinet>
<Application_Group>Customer</Application_Group>
<Purpose>Upgrade</Purpose>
</server>
I get the following output:
<?xml version="1.0"?> <Server
Name="pxtest01"><Serial_Number></Serial_Number></server>
Using the following code:
<?php
$doc = domxml_new_doc("1.0");
$root = $doc->add_root("Server");
$root->set_attribute("Name", "pxtest01");
$el = $doc->create_element("Serial_Number");
$root->append_child($el);
$text = $doc->create_text_node($el["000000"]);
$el->append_child($text);
print htmlentities($doc->dump_mem());
?>
Can someone help me fix my code so that when I add an element I can also set
some contents or a value for that element? example
<serial_number>0000000</serial_number>
Thank you!