开发者

c++. libxml2. < and > are replaced to &lt; and &gt; INSIDE tags

开发者 https://www.devze.com 2023-01-25 18:20 出处:网络
I\'m writing a library that creates xml tree from given data. The problem is that the data contains tags inside nodes.

I'm writing a library that creates xml tree from given data. The problem is that the data contains tags inside nodes. for example <node> "this is a very <bold>huge</bold> text" </node> quotes - just to separate text given to me=) When I create an xml using libxml and then write it to console (using xmlDumpMEmeory) I get: <node>this is a very &lt;bold&gt;huge&lt;/bold&gt; text</node>

I understand why it's so but have no idea开发者_StackOverflow中文版s how to fix that normally. The only solution I see is to manually replace < and > in my ::ToString() But are there any other symbols (like <,>) that I should replace?

Thx for attention


If you wish to embed special characters such as this in the element contents, they need to be wrapped as CDATA. A conformant XML implementation will always do what you noticed here.

libxml should have some way to write element contents as CDATA that should fix this for you. This looks promising:

Function: xmlTextWriterWriteCDATA

Write an xml CDATA.

0

精彩评论

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

关注公众号