Parsing XML with Colons in Tag Names Using PHP
SimpleXML may not be the ideal choice for parsing XML documents containing tags with colons, such as:
<xhtml:div>sample <xhtml:em>italic</xhtml:em> text</xhtml:div>
To parse such XML documents effectively, consider using an alternative library. The following solution demonstrates how to navigate and access elements with colons in their names using the SimpleXML library:
For the given XML document, you can access the 'em' element like this:
$xml->children('xhtml', true)->div->em;
However, accessing the 'date' field requires another step to exit the namespace.
$xml->children('xhtml', true)->div->children()->date;
The above is the detailed content of How Can I Parse XML Tags With Colons Using PHPSimpleXML?. For more information, please follow other related articles on the PHP Chinese website!