DOMDocument - createTextNode, encoding issue

谁说我不能喝 提交于 2019-12-02 15:13:58

问题


I have a problem with createTextNode method e special characters like '>', '<':

Dim xmlDoc As DOMDocument
Dim codeXML as String
Dim n As IXMLDOMNode

codeXML = '<data>value</data>'
Set n = xmlDoc.createTextNode(codeXML)

I need a result like this:

<main><data>value</data></main>

but I get

<main>&lt;data&gt;value&lt;/data&gt;</main>

How can I solve that problem?

Thank you very much.


回答1:


One way would be to create a second Document to serve as the XML parser for these XML literals. You can use LoadXML to pass the string in and get validated XML objects. You can then Import the node to the original/main DOM Document you are building.



来源:https://stackoverflow.com/questions/8785564/domdocument-createtextnode-encoding-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!