2

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.