• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XML Helper - generate XML quickly and easily

#1
[eluser]Jérôme Jaglale[/eluser]
Download and documentation

New XML document
Code:
$dom = xml_dom();

Add "book" element
Code:
$book = xml_add_child($dom, 'book');

Add "title" to "book"
Code:
xml_add_child($book, 'title', 'Hyperion');

Add "author" to "book"
Code:
$author = xml_add_child($book, 'author', 'Dan Simmons');

Add "birthdate" attribute to "author"
Code:
xml_add_attribute($author, 'birthdate', '1948-04-04');

Display XML document
Code:
xml_print($dom);


Output
Code:
<?xml version="1.0"?>
<book>
  &lt;title&gt;Hyperion&lt;/title&gt;
  <author birthdate="1948-04-04">Dan Simmons</author>
</book>

PHP 5 required. Based on DOMDocument.

#2
[eluser]Kami_[/eluser]
Well done!

This will definitely come in handy.

#3
[eluser]rezzz[/eluser]
The only issue here is that instead of
Code:
&lt;?xml version="1.0"?&gt;
<book>
  &lt;title&gt;Hyperion&lt;/title&gt;
  <author birthdate="1948-04-04">Dan Simmons</author>
</book>

it's really creating
Code:
&lt;?xml version="1.0"?&gt;
<book>
  &lt;title&gt;Hyperion
  <author birthdate="1948-04-04">Dan Simmons</author>
  &lt;/title&gt;
</book>

Anyone else notice this? Or better yet have an idea for a fix? Thank you very much!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.