php simple xml parse problem on invalid tags

how can i parse element like this example

<?php

$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
    <actor:view id='44' />
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#211;r</actor>
    <actor:view id='49' />
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
XML;


 $simpleXml = new SimpleXMLElement($xmlstr);

 var_dump((array) $simpleXml);

namespace error : Namespace prefix actor on view is not defined in /home/sweb/www/tmp/sxml.php on line 35

in /home/sweb/www/tmp/sxml.php on line 35

Upvotes: 2

Views: 621

Answers (1)

zneak
zneak

Reputation: 138031

XML parsers rely on the fact documents have to be strictly valid, and yours is not well-formed. It needs a namespace URI for actor. The root element should be along the lines of this:

<movies xmlns:actor="http://yoururl.com/">

As long as you don't have it, no compliant XML parser will accept your document.

Upvotes: 3

Related Questions