Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のようなXMLドキュメントがあります。
<items> <item id="1" name="CP_09550"/> <item id="2" name="CP_09551"/> <item id="3" name="CP_09552"/> </items>
CP_09550xmllintで ex: の name パラメータを使用して id 値を取得するにはどうすればよいですか?
CP_09550
ありがとう
値を取得するには、XPath 式をstring(...)ornumber(...)関数呼び出しにラップします。
string(...)
number(...)
xmllint --xpath 'string(/items/item[@name="CP_09550"]/@id)' test.xml
これは正確に を返す1ため、スクリプトで出力をさらに処理する必要はありません。
1