Parsing XML files using CodeIgniter?
Searching the, Internet ,I found http://blog.insicdesigns.com/2009/03/parsing-xml-file-using-codeigniters-simplexml-library/, but I have a lot of questions. I am new to codeigniter, and I am trying to adapt my code to this xml. I want to display once a user logins, but the question is, how would I iterate 开发者_JS百科through a series of child nodes with attributes?
A little code will be really helpfull
The class you've linked to is for PHP 4. If you're using PHP 4, obviously you should upgrade now. PHP 5 users should use the real deal, SimpleXML. Here's an example for PHP's SimpleXML. If you have questions about SimpleXML (PHP's, not CodeIgniter's knockoff) read the manual's examples a dozen times and if it still doesn't come to you, please post a new question.
$Comprobante = simplexml_load_file('yourfile.xml');
echo $Comprobante->Emisor['nombre'];
After you're done with $this->parser->parse
, you want to look at the paragraph that starts "Lets add the _getXML function to our controller" to see how to iterate through the parsed XML object. As for attributes, they're stored in the "@attributes"
property of the node with the attributes. Just do a search on the page for "attributes" and you'll get the very basic snippet of the library that assigns the attributes as well as comments asking your very question.
A good idea when you have a question about a blog post is always to try a search (on Windows, it's Ctrl+F) for your keywords. "attributes" shows up a number of times to answer your question.
精彩评论