XML -- Parsing / Updating / Adding to
Posted: Sat Nov 03, 2007 5:00 pm
feyd | Please use
And this is the error I get when it is uploaded and tested:
Why does this error occur?
Any help much appreciated
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi,
I scanned the google results for XML DOM, and found a couple of tutorials. One on [url]http://www.ibm.com/developerworks/library//x-xmlphp1.html[/url], and another from [url]http://devzone.zend.com/article/2387-XML-and-PHP-5[/url]. Using a little bit of both, I pieced together what I think should work to create a new XML file:Code: Select all
<?php
//New XML
$xml = new DOMDocument('1.0');
//specify the root element
$root = $xml->append_child($xml->create_element('users'));
//Add new user
$user = $root->append_child($xml->create_element('user'));
//Add the email
$email = $user->append_child($xml->create_element('email'));
//Add the contents of $email
$email->append_child($xml->create_text_node('jonah@nucleussystems.com'));
//format xml
$root->format_output = true;
//Save xml
$root->save('file.xml');
?>Code: Select all
Warning: domdocument(): Start tag expected, '<' not found in /home/content/g/e/i/geinternet/html/nucleussystems/XML/index.php on line 3
Warning: create_element(): Underlying object missing in /home/content/g/e/i/geinternet/html/nucleussystems/XML/index.php on line 6
Warning: create_element(): Cannot fetch DOM object in /home/content/g/e/i/geinternet/html/nucleussystems/XML/index.php on line 6
Fatal error: Call to a member function on a non-object in /home/content/g/e/i/geinternet/html/nucleussystems/XML/index.php on line 9Any help much appreciated
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]1.[/b] Select the correct board for your query. Take some time to read the guidelines in the sticky topic.[/quote]