Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mbpowner

macrumors regular
Original poster
Aug 19, 2016
174
14
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!
[doublepost=1479551496][/doublepost]Ps im a beginning coder and i need domdocument
 

960design

macrumors 68040
Apr 17, 2012
3,710
1,577
Destin, FL
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.