1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
<html>
<body>
<pre>
<?PHP
$dom = new DomDocument;
$dom->preserveWhiteSpace = FALSE;
$file = '../XMLData/example1b.xml';
$loadstate=$dom->load($file);
$xp = new DOMXPath($dom);
$xpathString="//car";
echo "<b>Example: ".$xpathString."</b><br>";
$nodes = $xp->query($xpathString);
foreach ($nodes as $node) {
$xpathString="./color";
echo "<b>Example: ".$xpathString."</b><br>";
$innernodes = $xp->query($xpathString,$node);
foreach ($innernodes as $innernode) {
echo " Name:".$innernode->nodeValue."<br>";
}
}
?>
</pre>
</body>
</html>
|