MY_Xml_Writer - Easy XML writer library |
[eluser]JoostV[/eluser]
This is a very easy to use XML writer library I developed to write XLM for communication with a Flash app. But it can be used to generate any well-formed XML document. Thought I'd share. Any comments welcome, of course ![]() EDIT: Most recent version is on Github: https://github.com/accent-interactive/xml_writer It can be used to create any XML, not matter how deep. Every branche and node can have one or more attributes, if needed. Need CDATA? Just set a parameter to true. The library prints XML directly to screen, setting XML headers first, or it can return the XML as a string. Just place the library in applications/library and you're good to go. Basically, you can add two types of data: * branches - you need to start a new branch and end it before adding the next branch * nodes - nodes are children to a branch. You do not have to start and end a node, just add it. Example use: place this in your controller (of course you would normally collect the data from a database, making the code much cleaner than it is in this example) CONTROLLER Code: function write_xml() { This will produce the following XML: Code: <?xml version="1.0" encoding="UTF-8"?> EXTRA OPTIONS Before you call initiate() you can set some XML settings if you wish: Code: $xml->setRootName($string); // Set the value of the root tag for this XML. Defaults to 'root' USE A VIEW If you do not wish to print, but rather send the XML string to a view file: Code: $data['xml'] = $xml->getXml(); LIBRARY SOURCE CODE The library code will be in the following post below.
[eluser]JoostV[/eluser]
LIBRARY SOURCE CODE Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
[eluser]JoostV[/eluser]
I also added this to the Wiki http://codeigniter.com/wiki/XML_generator_library/
[eluser]spheroid[/eluser]
Great library. Any way to set an ID for the root element, like: Code: <?xml version="1.0"?>
[eluser]JoostV[/eluser]
Yep, You can use all the methods in XMLWriter, which is a standard PHP5 class. http://nl.php.net/manual/en/book.xmlwriter.php Code: $xml->setRootName($string); Did not have time to test it, but it should work.
[eluser]spheroid[/eluser]
@JoostV: Wanted to say this is a great libary! I've been learning AJAX and needed to get XML responses back. This has definitely helped out a great deal!
[eluser]JoostV[/eluser]
Glad to be of help ![]() Actually, with Ajax, you might be better off using json output. It is not as verbose as XML and there are some great libraries out there to get you started writing json in a jiffy.
[eluser]Shimura[/eluser]
Hello JoostV, I need help about this library, how to make a loop with when i recover data in a array like this $xml->startBranch('car', array('country' => 'usa'));. And too i need to communicate my XML / SWF with a JS in a flashvar how make this with codeigniter ? Thank you. (I'm sorry about my English because i'm french).
[eluser]JoostV[/eluser]
I'm not quite sure what you mean, could you be more specific? Do you want to make a loop of cars? Producing something like Code: <cars>
[eluser]Shimura[/eluser]
Yes like this, For example i have my data with the table student and the bases id_student, first_name, last_name, year. The xml result : Code: <student_data> But the problem is about the controller to produce this with $data. And always the second problem, how communicate XML/SWF with codeigniter & AS3 ? because i don't see how i recover the file.xml ? Thank you, i appreciate your assistance. |
Welcome Guest, Not a member yet? Register Sign In |