PHP DOMDocument : How to parse custom XML/RSS tag names with COLONS? -


i have below rss parse, like:

<?xml version="1.0" encoding="utf-8"?> <rss xmlns:x-wr="http://www.w3.org/2002/12/cal/prod/apple_comp_628d9d8459c556fa#" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:x-example="http://www.example.com/rss/x-example" xmlns:x-microsoft="http://schemas.microsoft.com/x-microsoft" xmlns:xcal="urn:ietf:params:xml:ns:xcal" version="2.0">     <channel>         <item>             <title>about apples</title>             <author>david k. lowie</title>             <description>some description apples</description>             <xcal:description>this full description apples</xcal:description>         </item>         <item>             <title>about oranges</title>             <author>marry l. jones</title>             <description>some description oranges</description>             <xcal:description>this full description oranges</xcal:description>         </item>     </channel> </rss> 

in php, parse like:

$rss = new domdocument(); $rss->load( "http://www.example.com/books.rss" );  foreach( $rss->getelementsbytagname("item") $node ) {     echo $node->getelementsbytagname("title")->item(0)->nodevalue,     echo $node->getelementsbytagname("author")->item(0)->nodevalue,     echo $node->getelementsbytagname("description")->item(0)->nodevalue,     echo $node->getelementsbytagname("xcal:description")->item(0)->nodevalue, } 

i can read everything except xcal:description node there. (the node names that: description , xcal:description.)

  1. how parse (read) nodes like xcal:description
  2. is because of similar node names, like: description , xcal:description ?

(i can't change rss source since it's not under control.)

please kindly help.

use getelementsbytagnamens():

$node->getelementsbytagnamens("urn:ietf:params:xml:ns:xcal", "description")->item(0)->nodevalue 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -