从xml中提取详细信息的脚本 [英] script to extract the details from xml

查看:30
本文介绍了从xml中提取详细信息的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有如下xml文件:

if have any xml file as below:

<soap env="abc" id="xyz">
<emp>acdf</emp>
<Workinstance name="ab" id="ab1">
<x>1</x>
<y>2</y>
</Workinstance>
<projectinstance name="cd" id="cd1">
<u>1</u>
<v>2</v>
</projectinstance>
</soap>

我想使用 unix 脚本提取 workinstance 中的 id 字段

I want to extract the id field in workinstance using unix script

我尝试了 grep,但是它正在检索整个 xml 文件.有人可以帮助我如何获得它吗?

I tried grep but, it is retrieving the whole xml file. Can someone help me how to get it?

推荐答案

您可能需要考虑类似 XMLStarlet,它实现了 XPath/XQuery 规范.

You might want to consider something like XMLStarlet, which implements the XPath/XQuery specifications.

即使在最好的条件下,使用正则表达式解析 XML 基本上也是不可能的,因此您越早放弃尝试使用 grep 执行此操作,您的情况可能就越好.

Parsing XML with regular expressions is essentially impossible even under the best of conditions, so the sooner you give up on trying to do this with grep, the better off you're likely to be.

这篇关于从xml中提取详细信息的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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