Possible Duplicate:
Simplify PHP DOM XML parsing – how?
Here is my XML (c.xml):
<?xml version="1.0" encoding="utf-8"?>
<root>
<head>
<title id="title">Hello</title>
</head>
</root>
What I do:
$dom = new DOMDocument;
$dom->load('./c.xml');
var_dump($dom->getElementById('title'));die(); // returns NULL
What is the problem here&?
UPD
$dom->validate(); returns DOMDocument::validate(): no DTD found!
I think The Manual explains why this may happen
Potential fixes:
$dom->validate();, afterwards you can use$dom->getElementById(), regardless of the errors for some reason.Use XPath if you don’t feel like validating:
$x = new DOMXPath($dom);$el = $x->query("//*[@id='title']")->item(0);//Look for id=titleExample of using a custom DTD: