I've just recently begun learning XML in the context of PHP and Javascript, and I've encountered a problem.
So the issue is I want to put HTML markup within the XML, and then be able to extract this via PHP and embed the HTML in a different 开发者_StackOverflow中文版file that's reading the XML with SimpleXML. I'm echoing it with something along the lines of
echo $child->asXML();
However, of course the CDATA tags are still there and it doesn't work. So, my question is, is there either a way to A. embed HTML markup in a different way that is ignored by the XML parser but can be used in an HTML document, or B. a way to strip the CDATA tags from the code?
Just had to reload the string in the XML parser, but excluding CDATA.
echo simplexml_load_string($child->asXML(), null, LIBXML_NOCDATA)
Don't mind me.
The CDATA tags should disappear if you use the nodeValue
property instead of asXML()
.
Something like
echo $child->nodeValue;
should do the job.
精彩评论