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
.)
- how parse (read) nodes like
xcal:description
- 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.
$node->getelementsbytagnamens("urn:ietf:params:xml:ns:xcal", "description")->item(0)->nodevalue
Comments
Post a Comment