www.webdeveloper.com
Results 1 to 2 of 2

Thread: Xmlreader

  1. #1
    Join Date
    Apr 2014
    Posts
    2

    Unhappy Xmlreader

    I have a huge XML file, and I have to usr XMLREADER for matters of speed.

    My XML file can look sometinhg like this:

    Code:
    <root>
    <costumers>
    <name>AAAA</name>
    <name>BBBB</name>
    </costumers>
    <supliers>
    <name>XXXX</name>
    <name>ZZZZ</name>
    </supliers>
    </root>
    I nedd to output only the names of my COSTUMERS

    I Have tryed something like this:
    PHP Code:
    $xmlReader = new XMLReader();
    $xmlReader->open($FileName);
    while(
    $xmlReader->read()) {
        if(
    $xmlReader->nodeType == XMLReader::ELEMENT && $xmlReader->localName == 'costumers') {
            while (
    $xmlReader->read()) {
                if(
    $xmlReader->nodeType == XMLReader::ELEMENT) {
                    if(
    $xmlReader->localName == 'name') {
                        
    $xmlReader->read();
                        
    $name=$xmlReader->value;
                        echo 
    $name;
                    }
                }
    }}} 
    But outputs all the names of costumers and supliers.
    How can I contain the ouput for only the COSTUMERS tag?

  2. #2
    Join Date
    Apr 2014
    Posts
    34
    I've never read an XML file before using php so forgive me if this is wrong. But, isn't your second while loop just iterating over ALL the xml file and hence returning everything that is a 'name'. Surely you need put something in to only parse the 'costumers' tag?

    ----------------
    webdev_monkey
    www.online-webdev-tools.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles