Master-Zone Blog Technical Notes

25Sep/092

XML using PHP

This article helps those relatively new to using XML with PHP to write a short and uncomplicated XML file using the DOM in a PHP environment.

1. Create a new XML DOMDocument

$dom = new DomDocument('1.0', 'UTF-8');

Each XML document must have 1 and only 1 root element.

2. Create root node

$root = $dom->createElement('bookmarks');
$root = $dom->appendChild($root);

3. Create child node

$user = $dom->createElement('username', $userArray['Username']);
$root->appendChild($user);

4. Output XML

$xml_string = $dom->saveXML();
echo $xml_string;

Download

VN:F [1.7.5_995]
Rating: 0.0/10 (0 votes cast)

About Ahmed

UNIX Systems Administrator, obsessed with anything related to servers.
Tagged as: , Leave a comment
Comments (2) Trackbacks (0)
  1. Hello from Russia!
    Can I quote a post in your blog with the link to you?

    UN:F [1.7.5_995]
    Rating: 0.0/5 (0 votes cast)
  2. Yes sure, go on

    UA:F [1.7.5_995]
    Rating: 0.0/5 (0 votes cast)

Leave a comment


Trackbacks are disabled.