xml - PHP DOMDocument not returning or loading first elements -


i have problem loading xml document. xml file is

<?xml version="1.0" encoding="utf-8"?> <!doctype gallery [ <!element gallery (category*)> <!element category (image*)> <!element image (title,comment,password,owner,rating)> <!element title any> <!element comment any> <!element password any> <!element owner any> <!element rating any> <!attlist category name cdata #required> <!attlist image date cdata #required> ]> <gallery>     <category name="entertainment">         <image date="monday">             <title>1</title>             <comment>2</comment>             <password>3</password>             <owner>4</owner>             <rating>5</rating>         </image>         <image date="friday">             <title>11</title>             <comment>22</comment>             <password>33</password>             <owner>44</owner>             <rating>55</rating>         </image>     </category>     <category name="education">     </category>     <category name="relax">     </category>     <category name="sporting">     </category> </gallery> 

and php print xml is

    $doc = new domdocument();     $doc->validateonparse = true;     $doc->load(root_path."xml/data.xml");      if($doc->validate()) {         print_r($doc->savehtml());      }     else echo 'not validated ';     

and result is

2 3 4 5 22 33 44 55 

by way, cannot understand why first elements skipped. have problems select element this

$category = $doc->getelementbyid('entertainment');  if (!$category){     echo 'not found'; } 

which returns:

not found 

it makes no sense use savehtml on xml document because doesn't represent html. <title> element has semantic meaning in html , element doesn't displayed on page, why can't see 1 , 11.

i suspect you're failing select entertainment category because dtd doesn't indicate anywhere name attribute represents id. you'd need have in dtd:

<!attlist category name id #required> 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -