$ nano cpc.xml
<CloudFactory>
<cloud name="m"/>
<hub name="HUB100">
<vm type="Server" name="TFS01" mac="52:54:00:01:02:03"/>
<vm type="Desktop" name="UD1041" mac="52:54:00:01:02:06" vnc="5906"/>
</hub>
<hub name="HUB99">
<vm type="Server" name="TFS02" mac="52:54:00:01:02:04"/>
<vm type="Desktop" name="UD1042" mac="52:54:00:01:02:06" vnc="5906"/>
</hub>
<bridge outside="br0" inside="HUB100">
<vm name="G1" outmac="52:54:00:01:ff:01" inmac="52:54:00:01:ff:02"/>
</bridge>
<nat outside="Default" inside="HUB100">
<vm name="N1" outmac="52:54:00:01:ff:01" inmac="52:54:00:01:ff:02"/>
</nat>
<router outside="HUB100" inside="HUB99">
<vm name="R1" outmac="52:54:00:01:ff:03" inmac="52:54:00:01:ff:04"/>
</router>
</CloudFactory>
xpath 命令資訊查詢
1. 取出所有 hub 定義內容
$ xpath -q -e "//hub" cpc.xml <hub name="HUB100">
<vm type="Server" name="TFS01" mac="52:54:00:01:02:03" />
<vm type="Desktop" name="UD1041" mac="52:54:00:01:02:06" vnc="5906" />
</hub>
<hub name="HUB99">
<vm type="Server" name="TFS02" mac="52:54:00:01:02:04" />
<vm type="Desktop" name="UD1042" mac="52:54:00:01:02:06" vnc="5906" />
</hub>
2. 取出所有 hub 標籤的 name 屬性內容
$ xpath -q -e "//hub/@name" cpc.xml
name="HUB100"
name="HUB99"
3. 先取出 name 屬性內容是 "HUB99" 的所有 hub 標籤, 然後顯示所有 vm 標籤的 mac 位址
$ xpath -q -e "//hub[@name='HUB99']/vm/@mac" cpc.xml
mac="52:54:00:01:02:04"
mac="52:54:00:01:02:06"
沒有留言:
張貼留言