libxml2保留空标签 [英] libxml2 preserve empty tags

查看:178
本文介绍了libxml2保留空标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

libxml2(对于C)不会在保存时保留其原始形式的空元素.它用<tag/>替换<tag></tag>,这在技术上是正确的,但会给我们带来麻烦.

libxml2 (for C) is not preserving empty elements in their original form on a save. It replaces <tag></tag> with <tag/> which is technically correct but causes problems for us.

xmlDocPtr doc = xmlParseFile("myfile.xml");
xmlNodePtr root = xmlSaveFile("mynewfile.xml", doc);

我尝试使用各种选项(使用xlmReadFile),但似乎没有一个会影响输出.这里的一篇文章提到禁用标签压缩,但是该示例是针对PERL的,而我发现C没有类似物.

I've tried playing with the various options (using xlmReadFile) but none seem to affect the output. One post here mentioned disabling tag compression but the example was for PERL and I've found no analog for C.

是否有禁用此行为的选项?

Is there an option to disable this behavior?

推荐答案

只需在

Just found this enum in the xmlsave module documentation:

 Enum xmlSaveOption {
     XML_SAVE_FORMAT = 1 : format save output
     XML_SAVE_NO_DECL = 2 : drop the xml declaration
     XML_SAVE_NO_EMPTY = 4 : no empty tags
     XML_SAVE_NO_XHTML = 8 : disable XHTML1 specific rules
     XML_SAVE_XHTML = 16 : force XHTML1 specific rules
     XML_SAVE_AS_XML = 32 : force XML serialization on HTML doc
     XML_SAVE_AS_HTML = 64 : force HTML serialization on XML doc
     XML_SAVE_WSNONSIG = 128 : format with non-significant whitespace
 }

也许您可以重构您的应用程序以使用此模块进行序列化,并在这些选项上有所作为.特别是XML_SAVE_NO_EMPTY.

Maybe you can refactor your application to use this module for serialization, and play a little with these options. Specially with XML_SAVE_NO_EMPTY.

这篇关于libxml2保留空标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆