輸入 XML 看起來像幾個塊:
<Parties>
<Party compid="CUST1" side="1">
<Connections>
<SocketConnection listenport="9029" />
</Connections>
</Party>
</Parties>
我的目標是向每個客戶提取他的特定參數,例如:compid;listenport
現在我可以讓所有客戶使用
xmlstarlet fo -D config.xml | xmlstarlet select -T -t -m '//Parties/Party' -v '@compid' -nl
下一步是讓每個客戶循環獲取他的監聽端口,但是
xmlstarlet fo -D config.xml | xmlstarlet select -T -t -m '//Parties/Party[@compid="CUST1"]' -v 'Connections/SocketConnection/@listenport'
或任何其他嘗試不返回任何內容。我在過濾時遺漏了什麼[@value=string]
嗎?
提前致謝!
用你的例子和xmlstarlet
:
xmlstarlet select --text --template --match '//Parties/Party' --value-of \
'concat(@compid,";",Connections/SocketConnection/@listenport)' -n config.xml
輸出:
CUST1;9029
看: xmlstarlet select --help
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句