XML 数据提取 [英] XML Data extraction

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

问题描述

<Filer>
<ID>123456789</ID>
<Name>
<BusinessNameLine1>Stackoverflow</BusinessNameLine1>
</Name>
<NameControl>stack</NameControl>
<USAddress>
<AddressLine1>123 CHERRY HILL LANE</AddressLine1>
<City>LA</City>
<State>CA</State>
<ZIPCode>90210</ZIPCode>
</USAddress>
</Filer>

这里有一个给我的 xml 代码示例.有了这个 xml,我需要从这个 xml 中掌握某个属性.

Here I have a sample of xml code given to me. With this xml I need to grasp a certain attribute from this xml.

我只需要从文件中提取所有 <BusinessNameLine1>.问题是这个标签在整个文件中出现多次,但我只需要在 <Filer> 标签中它为假时提取它.

I simply need to extract all the <BusinessNameLine1> from the file. The issue is that this tag appears multiple times through out the file but I only need to extract it if it false in the <Filer> Tag.

我会使用 PHP 执行此操作,但我正在工作,由于无法在我的计算机上安装软件,我无法运行 php 代码.但是,我可以执行 bash 文件.该文件也非常大,所以我不能把它放在excel中.我不知道该怎么做.我将不胜感激有关从哪里开始的帮助或指导.

I would do this with PHP but I am at work and I am not able to run php code due to not being able to install software on my computer. I can execute bash files however. The file is also extremely large so I can not put it in excel. I have no idea how to do this. I would appreciate some help or guidance on where to start.

推荐答案

你可以试试这个组合的 awk 和 sed 命令,

You could try this combined awk and sed commands,

$ awk -v RS='</Filer>' '/^<Filer>/ {gsub (/
/," "); print}' file | sed -r 's/.*<BusinessNameLine1>([^<]*)</BusinessNameLine1>.*/1/g'
Stackoverflow

这篇关于XML 数据提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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