xmlstarlet从Office 365 XML文件中提取值

时间:2016-11-05 15:28:45

标签: xslt xml-parsing xmlstarlet

我正在尝试从http://go.microsoft.com/fwlink/?LinkId=533185中提取Office 365产品组合中每个产品的IPv4地址和URL。我想创建一个输入文件来更新防火墙和代理服务器规则。

XML文件的片段

<?xml version="1.0" encoding="utf-8"?>
<products updated="8/31/2016">
  <product name="WAC">
    <addresslist type="IPv6">
      <address>2a01:111:f406:8800::/64</address>
      <address>2a01:111:f406:400::/64</address>
      <address>2a01:111:f406:1c01::/64</address>
      <address>2a01:111:f406:9400::/64</address>
      <address>2a01:111:f406:2402::/64</address>
      <address>2a01:111:f406:a804::/64</address>
      <address>2a01:111:f406:b401::/64</address>
      <address>2620:1ec:c11::204</address>
      <address>2a01:111:202c::204</address>
      <address>2620:1ec:c11::205</address>
      <address>2a01:111:202c::205</address>
    </addresslist>
    <addresslist type="IPv4">
      <address>13.69.187.20/32</address>
      <address>13.70.184.242/32</address>
      <address>13.71.155.176/32</address>
      <address>13.75.153.216/32</address>
      <address>13.76.140.48/32</address>
      <address>13.78.114.39/32</address>
      <address>13.85.84.102/32</address>
      <address>13.88.248.161/32</address>
      <address>13.88.254.212/32</address>
      <address>13.94.209.165/32</address>
      <address>23.103.183.15/32</address>
      <address>40.68.166.51/32</address>
      <address>40.74.130.243/32</address>
      <address>40.74.138.42/32</address>
      <address>40.76.54.124/32</address>
      <address>40.86.230.88/32</address>
      <address>40.114.192.209/32</address>
      <address>40.117.226.146/32</address>
      <address>40.126.236.216/32</address>
      <address>40.127.79.139/32</address>
      <address>52.169.109.48/32</address>
      <address>52.172.13.171/32</address>
      <address>52.172.153.104/32</address>
      <address>52.175.25.142/32</address>
      <address>52.232.128.169/32</address>
      <address>104.40.225.204/32</address>
      <address>104.41.62.54/32</address>
      <address>104.211.103.207/32</address>
      <address>104.211.229.230/32</address>
      <address>104.214.38.136/32</address>
      <address>104.215.194.17/32</address>
      <address>134.170.27.86/32</address>
      <address>134.170.48.20/32</address>
      <address>134.170.48.22/32</address>
      <address>134.170.65.86/32</address>
      <address>134.170.170.86/32</address>
      <address>137.116.172.39/32</address>
      <address>137.135.65.72/32</address>
      <address>191.235.87.181/32</address>
      <address>191.237.40.220/32</address>
    </addresslist>
    <addresslist type="URL">
      <address>*.officeapps.live.com</address>
      <address>*.cdn.office.net</address>
    </addresslist>
  </product>
  <product name="Sway">

我已经想出了可以用来循环产品以获得最终结果的产品,但我似乎可以通过过滤特定产品和IPv4地址。

./xmlstarlet sel -t -m '/products/product'  -v @name -n Downloads/O365IPAddresses.xml
WAC
Sway
Planner
Yammer
OneNote
OfficeiPad
OfficeMobile
ProPlus
RCA
LYO
SPO
Office365Video
identity
EXO
CRLs
o365
EOP

我尝试了以下的许多变体而没有输出。

./xmlstarlet sel -t -m '//root/products/product[name="WAC"]/addresslist[type="IPv4"]'  Downloads/O365IPAddresses.xml

最终,我想找到一个类似于以下内容的文本文件。

WAC,IPv4,13.69.187.20/32
WAC,IPv4,13.70.184.242/32
.....
.....
WAC,URL,*.officeapps.live.com

然后,我可以使用此csv文件更新公司中的防火墙和代理服务器的集合。

非常感谢您的帮助。

0 个答案:

没有答案