开发者

SimpleXML -- Strip CDATA Tags (or embed HTML markup in XML) [closed]

开发者 https://www.devze.com 2023-01-11 06:34 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号