0

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 through a series of child nodes with attributes? alt text

A little code will be really helpfull

4
  • dont quite understand your requirements, but one way you can iterate through an XML file is using foreach Commented Nov 23, 2010 at 19:33
  • Please don't post screenshots of your code. They get resized down to the point where the text is illegible, and we can't copy/paste from them even if they're reasonably sized. Commented Nov 23, 2010 at 19:36
  • Reasonably sized: i.imgur.com/OcVku.jpg Commented Nov 23, 2010 at 19:37
  • sorry for than I just want to adapt the code of the page to iterate over my xml, the one that is displayed, thanks for your answers, I know that is using a foreach but hwo do I take for example comprobante?? Commented Nov 23, 2010 at 19:39

2 Answers 2

4

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'];
Sign up to request clarification or add additional context in comments.

1 Comment

+1 for recommending the PHP5 SimpleXML lib (it's perfect for simpler things).
1

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.

2 Comments

thanks for your answer, so with that snippet of code I can iterate to alll my nodes and subnodes right?
Your usual XML node (I don't know the spec, actually, so this is just speaking from experience) will contain either a text element (sometimes CDATA) or other nodes. If it contains other nodes, just access them like you did from the parent node.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.