I’m receiving an XML file via API and parsing it with PHP / SimpleXML / XPath.
I need to take data from one of the fields that contains HTML and output it, however the HTML is all prefixed with a “h:” namespace.
Example XML:
<xmlfeed>
<title>Title Here</title>
<a:content xmlns:a="http://www.w3.org/2005/Atom" xmlns:h="http://www.w3.org/1999/xhtml">
<h:table xmlns:h="http://www.w3.org/1999/xhtml" width="1360" height="259" cellspacing="0" cellpadding="0" border="0">
<h:tbody><h:tr><h:td width="35%" colspan="3"></h:td></h:tr></h:tbody>
</h:table>
<h:h3 xmlns:h="http://www.w3.org/1999/xhtml">Test heading here</h:h3>
<h:a href="link.php">Link Here</h:a>
</a:content>
</xmlfeed>
How can I parse all the HTML within a:content to remove the “h:” prefix from each element as well as the namespaces?
Thank you.
I must have glossed over this in the documentation.
It took a little while to find, but the following seems to work well:
Hope this helps someone else trying to solve the same issue.