DOMdocument

Discussion in 'Web Design and Development' started by mbpowner, Nov 19, 2016.

  1. mbpowner macrumors regular

    Joined:
    Aug 19, 2016
    #1
    not sure why it doesnt work for me

    So lets say there is this:

    <technology>

    <computer>
    <name></name>
    <model></model>
    </computer>

    <computer>
    <name></name>
    <model></model>
    </computer>
    Etc...
    </technology>

    how can you use domdocument to find all the elements with the name tag and print the models of all of them?

    Thanks!
    --- Post Merged, Nov 19, 2016 ---
    Ps im a beginning coder and i need domdocument
     
  2. 960design macrumors 68020

    Joined:
    Apr 17, 2012
    Location:
    Destin, FL
    #2
    I'm really guessing at what you are attempting to accomplish... hopefully this will point you in the proper direction?
    Code:
    <?php
    $xml = <<< XML
    <?xml version="1.0" encoding="utf-8"?>
    <books>
     <book>Patterns of Enterprise Application Architecture</book>
     <book>Design Patterns: Elements of Reusable Software Design</book>
     <book>Clean Code</book>
    </books>
    XML;
    
    $dom = new DOMDocument;
    $dom->loadXML($xml);
    $books = $dom->getElementsByTagName('book');
    foreach ($books as $book) {
        echo $book->nodeValue, PHP_EOL;
    }
    ?>
    
    Source:
    http://php.net/manual/en/domdocument.getelementsbytagname.php
     
  3. mbpowner thread starter macrumors regular

    Joined:
    Aug 19, 2016

Share This Page