Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP library for parsing XML with a colons in tag names? [duplicate]

I've been trying to use SimpleXML, but it doesn't seem to like XML that looks like this:

<xhtml:div>sample <xhtml:em>italic</xhtml:em> text</xhtml:div> 

So what library will handle tags that look like that (have a colon in them)?

like image 726
mpen Avatar asked Oct 16 '09 00:10

mpen


1 Answers

Say you have some xml like this.

<xhtml:div>   <xhtml:em>italic</xhtml:em>   <date>2010-02-01 06:00</date> </xhtml:div> 

You can access 'em' like this: $xml->children('xhtml', true)->div->em;

however, if you want the date field, this: $xml->children('xhtml', true)->div->date; wont work, because you are stuck in the xhtml namespace.

you must execute 'children' again to get back to the default namespace:

$xml->children('xhtml', true)->div->children()->date; 
like image 188
Nathan Avatar answered Sep 21 '22 23:09

Nathan