从一个简单的XML文件中的数据的提取 [英] Extraction of data from a simple XML file
问题描述
我有一个XML文件的内容:
I've a XML file with the contents:
<?xml version="1.0" encoding="utf-8"?>
<job xmlns="http://www.sample.com/">programming</job>
我需要一种方法来提取什么是在&LT;工作..&GT;
&LT; /工作&GT;
标签,编程与在这种情况下。这应该在Linux命令提示符下进行,使用grep / sed的/ awk的。
I need a way to extract what is in the <job..>
</job>
tags, programmin in this case. This should be done on linux command prompt, using grep/sed/awk.
推荐答案
你真的有只使用这些工具?他们不是为XML处理,虽然它可能得到的东西的作品大部分时间确定,它将会失败边缘的情况下,像编码,换行等。
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.
我建议xml_grep:
I recommend xml_grep:
xml_grep 'job' jobs.xml --text_only
这给输出:
programming
在Ubuntu / Debian的,xml_grep是在XML-树枝的工具包。
On ubuntu/debian, xml_grep is in the xml-twig-tools package.
这篇关于从一个简单的XML文件中的数据的提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!