处理xml的命令工具
2016-07-01 18:32
295 查看
down vote | XMLStarlet or another XPath engine is the correct tool for this job. For instance, with data.xmlcontaining the following: <root> <item> <title>15:54:57 - George:</title> <description>Diane DeConn? You saw Diane DeConn!</description> </item> <item> <title>15:55:17 - Jerry:</title> <description>Something huh?</description> </item> </root> ...you can extract only the first title with the following: xmlstarlet sel -t -m '//title[1]' -v . -n <data.xml Trying to use sed for this job is troublesome. For instance, the regex-based approaches won't work if the title has attributes; won't handle CDATA sections; won't correctly recognize namespace mappings; can't determine whether a portion of the XML documented is commented out; won't unescape attribute references (such as changing Brewster & Jobsto Brewster & Jobs), and so forth. 、、、、、、、、、、、、、、、、、、、、、、、、、、、、、 Do you really have to use only those tools? They're not designed for XML processing, and although it's possible to get something that works OK most of the time, it will fail on edge cases, like encoding, line breaks, etc. I recommend xml_grep: xml_grep 'job' jobs.xml --text_only Which gives the output: programming On ubuntu/debian, xml_grep is in the xml-twig-tools package. |
相关文章推荐
- XML 与 JSON 优劣对比
- As3.0 xml + Loader应用代码
- 网马生成器 MS Internet Explorer XML Parsing Buffer Overflow Exploit (vista) 0day
- ext读取两种结构的xml的代码
- 实例解析Ruby程序中调用REXML来解析XML格式数据的用法
- Ruby中XML格式数据处理库REXML的使用方法指南
- C#中如何使用 XmlReader 读取XML文件
- C#针对xml基本操作及保存配置文件应用实例
- Ruby使用REXML库来解析xml格式数据的方法
- Ruby程序中创建和解析XML文件的方法
- Ruby的XML格式数据解析库Nokogiri的使用进阶
- asp下查询xml的实现代码
- sqlserver FOR XML PATH 语句的应用
- 使用sp_xml_preparedocument处理XML文档的方法
- EBS xml publisher中文乱码问题及解决办法
- C#中的Linq to Xml详解
- C#操作XML文件实例汇总
- C# XML序列化方法及常用特性总结分析
- SQL Server中的XML数据进行insert、update、delete