从一个简单的XML文件中的数据的提取 [英] Extraction of data from a simple XML file

查看:1115
本文介绍了从一个简单的XML文件中的数据的提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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屋!

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