简体   繁体   中英

how to get a particular tag from xml file through curl command?

i have a file called startup-cfg.xml containing

<futurePbRst>
  <fsPbProviderStpStatus>enabled</fsPbProviderStpStatus>
</futurePbRst>
<fsPbRstCVlanBridgeTable>
  <fsPbRstCVlanBridgeEntry>
    <fsPbRstPort>1</fsPbRstPort>
  </fsPbRstCVlanBridgeEntry>
</fsPbRstCVlanBridgeTable>
<fsPbRstCVlanPortInfoTable>
  <fsPbRstCVlanPortInfoEntry>
    <fsPbRstPort>1</fsPbRstPort>
    <fsPbRstCepSvid>1</fsPbRstCepSvid>
  </fsPbRstCVlanPortInfoEntry>
</fsPbRstCVlanPortInfoTable>

<interface>
  <name>eth0</name>
</interface>
<interface>
  <name>lo</name>
</interface>
<interface>
  <name>pan0</name>
</interface>
<interface>
  <name>sim0</name>
</interface>
<interface>
  <name>sim1</name>
</interface>

i want to fire a curl command to get a particular tag value from this xml file.how can i do it?

running the command curl http://127.0.0.1:50000/netconf/startup-cfg.xml gives the entire file contents as output.

curl doesn't parse XML. Try piping curl 's output to xmllint :

curl http://127.0.0.1:50000/netconf/startup-cfg.xml \
| xmllint --xpath '//futurePbRst/fsPbProviderStpStatus/text()' -

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM