views:

490

answers:

2

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)?

+5  A: 

Colon denotes an XML namespace. The DOM has good support for namespaces.

Ollie Saunders
SimpleXML probably does too, but the OP is looking for a tag "xhtml:div" instead of just "div".
Matthew Scharley
Ohhh! Didn't realize that was a namespace. In that case, I might be able to get this to work... *runs back to the drawing board*
Mark
SimpleXML has *some* stuff for dealing with it, but I still can't get it to work right.
Mark
+2  A: 

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;

Namespaces always seem to cause endless problems... If you ask me they are pure architectural flair thrown in to solve a bunch of problems that don't actually exist in the real world.

Nathan Reed
I have to agree :)
Mark