本文介绍了使用PHP XMLWriter :: writeElement时保留XML代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mySQL表,其中包含复制的字段被转换为XML。 mySQL字段中的一些副本在这些单词周围有粗体标签:



< b>这将是粗体< / b>不会是



然而,当我使用,副本最终如下所示:



& lt; b& gt这将是粗体& lt; / b& gt,这不会是



任何人都可以建议我如何避免这些标签的字符编码?

解决方案

我猜你的代码需要使用,而不是。



请注意,如果您确信数据库中的内容将是正确的XML,那只会是一个很好的解决方案。否则,您需要首先通过DOM解析器运行该内容,例如 rel = nofollow> DOMDocument :: recover 标志设置,然后使用导出内容DOMDocument :: saveXML 并将其传递给 XMLWriter :: writeRaw


I have a mySQL table with fields containing copy that's being turned into XML. Some of the copy in the mySQL fields has bold tags around the words:

<b>This will be bold</b>, this won't be.

However, when I come to build my XML document using XMLwriter, the copy ends up looking like this:

&lt;b&gt;This will be bold&lt;/b&gt;, this won't be

Can anyone advise me on how I can avoid character encoding for these tags?

解决方案

I am guessing your code needs to use XMLWriter::writeRaw instead of XMLWriter::text.

Note that this will only be a good solution if you are confident the content in the database will be proper XML. Otherwise, you will need to first run that content through a DOM parser like DOMDocument::loadXML with the DOMDocument::recover flag set, and then export the content with DOMDocument::saveXML and pass it to XMLWriter::writeRaw.

这篇关于使用PHP XMLWriter :: writeElement时保留XML代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 22:19