CodeIgniter Forums
XML Helper - generate XML quickly and easily - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: XML Helper - generate XML quickly and easily (/thread-17023.html)



XML Helper - generate XML quickly and easily - El Forum - 03-23-2009

[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.


XML Helper - generate XML quickly and easily - El Forum - 03-24-2009

[eluser]Kami_[/eluser]
Well done!

This will definitely come in handy.


XML Helper - generate XML quickly and easily - El Forum - 01-07-2010

[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!