从xml文件中提取或grep值



我正在使用xgrep和xmlgrep从XML文件中查找某些信息(http://pastebin.com/1BJEWVJJ)

示例片段

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd">
<cXML xml:lang="en" payloadID="2015-02-24T14:17:26_3764135.ConfirmationRequest@axis.mincom.com" timestamp="2015-02-24T14:17:26+10:00">
<Header>
<From>
<Credential domain="SpotlessBranchID">
<Identity>
L678</Identity>
</Credential>
<Credential domain="SupplierCustno">
<Identity>
SPOWOC</Identity>
</Credential>
<Credential domain="MincomAxis">
<Identity>
101000026139003</Identity>
</Credential>
</From>
<To>
<Credential domain="SpotlessSAPSupplierID">
<Identity>
0002010354</Identity>
</Credential>
<Credential domain="SpotlessSupplierID">
<Identity>
0002010354</Identity>
</Credential>

我想提取SpotLessSupplierID标识值(例如0002010354)

我尝试了xgrep -s 'Credential:Identity/.*/' PO_3764135.xml,但输出太多("凭证"太多)

<!--         Start of node set (Search: Credential:Identity/.*/)                 -->
<!--         Node   0 in node set               -->
<Credential domain="SpotlessBranchID">
  <Identity>L678</Identity>
</Credential>
<!--         Node   1 in node set               -->
<Credential domain="SupplierCustno">
  <Identity>SPOWOC</Identity>
</Credential>
<!--         Node   2 in node set               -->
<Credential domain="MincomAxis">
  <Identity>101000026139003</Identity>
</Credential>
<!--         Node   3 in node set               -->
<Credential domain="SpotlessSAPSupplierID">
  <Identity>0002010354</Identity>
</Credential>
<!--         Node   4 in node set               -->
<Credential domain="SpotlessSupplierID">
  <Identity>0002010354</Identity>
</Credential>
<!--         Node   5 in node set               -->
<Credential domain="MincomAxis">
  <Identity>101000321896001</Identity>
</Credential>
<!--         Node   6 in node set               -->
<Credential domain="SpotlessBranchID">
  <Identity>L678</Identity>
</Credential>
<!--         Node   7 in node set               -->
<Credential domain="MincomAxisTPID">
  <Identity>101000026139</Identity>
</Credential>
<!--         End of node set                    -->

XmlStarlet在这些情况下是一个非常有用的工具,您可以下载它并尝试以下操作:

xmlstarlet sel -t -m "//header/To/Credential[@domain = 'SpotlessSAPSupplierID']" -v Identity -n /path_to_your_xml_file

对于文档:这是一个最佳链接:XmlStarlet

相关内容

  • 没有找到相关文章

最新更新