2016-04-01 11 views
-1

Ich versuche XML zu verwenden, um die Ergebnisse eines XML-Feeds in PHP anzuzeigen.simpleXML mit doppeltem Doppelpunkt

Hier ist mein PHP

$url = 'http://somefeed.xml'; 
$xml = file_get_contents($url); 
$xml = simplexml_load_string($xml); 


foreach($xml->entry as $x) { 
    echo "Name".$x->title."<br>"; 

} 

Hier ist ein out in der XML-Datei, die ich

<entry> 
     <id>test ed</id> 
     <title type="text">My House</title> 
     <updated>2016-03-31T22:45:06Z</updated> 
     <content type="application/xml"> 
      <s:organisationSummary> 
       <s:name>my house</s:name> 
       <s:odsCode>61bv</s:odsCode> 
       <s:address> 
        <s:addressLine>House Name</s:addressLine> 
        <s:addressLine>House Road</s:addressLine> 
        <s:addressLine>House Town</s:addressLine> 
        <s:postcode>House Postode</s:postcode> 
       </s:address> 
      </s:organisationSummary> 
     </content> 
    </entry> 

Mit dem PHP ich geschrieben habe, es zeigt den Titel perfekt, anzuzeigen versuchen aber Ich weiß nicht, wie ich die Details zu s: organizationSummary anzeigen soll. Ich möchte, dass sie den s: Name und jeden der s: addressLine Tags einzeln wiedergeben können.

Jede Hilfe wäre willkommen.

Antwort

0

Der Teil vor dem Doppelpunkt wird als Namespacepräfix bezeichnet. Eine Möglichkeit, den Zugriff auf Element im Namensraum verwendet xpath() Verfahren, zum Beispiel:

foreach($xml->entry as $x) { 
    echo $x->xpath("content/s:organisationSummary/s:name")[0]."<br>"; 
} 

Verwandte: Parse XML with Namespace using SimpleXML