Linux C语言调用libxml2的库文件。格式化xml文件,让rootElement的闭合标签新起一行!
2011-12-16 18:22
716 查看
好久没有更新了.其实这周在写东西,东西没出来,就没有写博客了.
刚才发现一个超级恶心的问题.
我用libxml读取xml数据,然后插入一个数据。但是居然是一行,而没有新起一行。怎么办呢,我就搜libxml format 和xmlSaveFormatFile ,还是有不少这样的问题的。还有人说这是一个bug,其实很恶心的很好笑的。
在libxml2的 $PREFIX/share/gtk-doc/html/libxml2/libxml2-tree.html#xmlSaveFormatFileEnc 有这样的一个解释.
最后一个参数是format,=1的时候就可以format,但是,当 下面两个全局变量 值被设置 才管用。
有这两个参数并进行设置才可以管用。在xmlSaveFormatFile前面加入这两行,运行不管用。
然后搜索。最后看到一个说用xmlReadFile而不是xmlParseFile解析文件。
发现貌似还不管用。后来发现,在这个解析xml文件前面加上 上面的两个全局变量,终于有换行了。而且还自动格式化了xml文件。不管用那个都管用。
所以这不是一个bug,而是一个调用先后的问题。但是上面的函数 解释的,一点也没有申明这一点。所以,反正现在可以格式化xml文件了,很好的。。
附上一些我搜索到的一些资料链接:
http://www.cppblog.com/lymons/archive/2009/03/30/37553.html
http://westsoftware.blog.163.com/blog/static/2609410920072175245763/ 这里有一个中文版本的文档.示例很重要.有了示例好办事情了.
刚才发现一个超级恶心的问题.
我用libxml读取xml数据,然后插入一个数据。但是居然是一行,而没有新起一行。怎么办呢,我就搜libxml format 和xmlSaveFormatFile ,还是有不少这样的问题的。还有人说这是一个bug,其实很恶心的很好笑的。
在libxml2的 $PREFIX/share/gtk-doc/html/libxml2/libxml2-tree.html#xmlSaveFormatFileEnc 有这样的一个解释.
xmlSaveFormatFile () int xmlSaveFormatFile (const char * filename, xmlDocPtr cur, int format) Dump an XML document to a file. Will use compression if compiled in and enabled. If @filename is "-" the stdout file is used.
If @format is set then the document will be indented on output.
Note that @format = 1 provide node indenting only if xmlIndentTreeOutput = 1 or xmlKeepBlanksDefault(0) was called。
filename: the filename (or URL) cur: the document format: should formatting spaces been added Returns: the number of bytes written or -1 in case of failure.
最后一个参数是format,=1的时候就可以format,但是,当 下面两个全局变量 值被设置 才管用。
xmlKeepBlanksDefault(0) ;//libxml2 global variable . xmlIndentTreeOutput = 1 ;// indent .with \n
有这两个参数并进行设置才可以管用。在xmlSaveFormatFile前面加入这两行,运行不管用。
然后搜索。最后看到一个说用xmlReadFile而不是xmlParseFile解析文件。
doc1 = xmlParseFile(docname); //doc1 = xmlReadFile(docname, NULL, XML_PARSE_NOBLANKS);
发现貌似还不管用。后来发现,在这个解析xml文件前面加上 上面的两个全局变量,终于有换行了。而且还自动格式化了xml文件。不管用那个都管用。
所以这不是一个bug,而是一个调用先后的问题。但是上面的函数 解释的,一点也没有申明这一点。所以,反正现在可以格式化xml文件了,很好的。。
附上一些我搜索到的一些资料链接:
http://www.cppblog.com/lymons/archive/2009/03/30/37553.html
http://westsoftware.blog.163.com/blog/static/2609410920072175245763/ 这里有一个中文版本的文档.示例很重要.有了示例好办事情了.
相关文章推荐
- 用XmlTextWriter写出的XML文件没有换行,用记事本打开XML文件的时候都写在了一行上,请问怎样加入换行!
- 一行代码完成 调用系统相册 和 视频,语音库,选择图片,视频,和音频文件。在选择界面实现了录制视频和录制音频功能。 截图
- 第一个go的web程序;调用七牛云存储的音频api问题解决;条件搜寻文件中的内容,字符串拼接+在上一行
- 序列化xml文件,标签闭合全部显示出来
- 一个很有用的vimrc文件(添加抬头,产生cpp初始程序,添加注释,注释一行,自动K&R格式化,taglist)
- 【涉及到python的小项目:openCV人脸识别(一)】在csv文件中的每一行信息后面添加数字标签
- 用XSLT文件在浏览器格式化显示XML文件
- Java代码调用操作系统可执行文件打开相应文件一行代码实现
- Domj4读取XML文件--实现获取XML文件中所有的标签节点
- Libxml2如何生成格式化的XML文件
- cocos2dx中调用TinyXml读取xml配置文件 || cocos2d-x 中跨平台tinyxml读取xml文件方式
- 利用Air中File类写入xml文件,以及XML文件存入时的格式化
- Struts-config.xml文件配置文件中的几个标签的顺序
- Node.js实现的指定目录xml文件标签对去除及转换为txt文本文件
- 使用input type=file标签进行文件上传时,在安卓手机中的微信浏览器中不能调起相机,但是在苹果手机中的微信浏览器中可以调用相机。解决办法很简单, <input type="file" nam
- dom4j处理xml文件,读取xml字符串,格式化xml文件
- file标签之act=read(只需一行代码读出文件内容)
- 将扫描的格式化文件转换成xml文件
- 织梦实现一个标签调用不同的文件