tags:

views:

33

answers:

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

+3  A: 

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/"&gt;

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

zneak
A: 

Thanks. It's OK but i have another problem. i can't access some elements look at this.

<?php
    $sxe = new SimpleXMLElement('http://rss.news.yahoo.com/rss/topstories', NULL, TRUE);

    var_dump((array) $sxe->channel->item);

see source of that rss. element media:content not access-able

also i use this method: $node->{'media:content'} but i cant parse that element?

sweb
This is not how stackoverflow works. If you want to refine your question use the "edit" link/button. If you have another question use the "Ask question" button.
VolkerK
Stack Overflow is not a forum. Here, people solve _one_ question at a time. I recommend you make another question for this issue, since it doesn't even use the same XML document. (Also, see the check marks under the question scores? When you check it, it means the answer solved your problem. You might consider using it on my answer if it solved your first problem.)
zneak