Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

xml - Get xmllint to output xpath results -separated, for attribute selector

How can I get xmllint to output multiple results of xpath selector for attributes "per line"?

Take this example:

  <?xml version="1.0" encoding="ISO-8859-1"?>
  <config>
          <tagX key1="value1 " key2=" value2"/>
          <tagY key3="value3" key4=" value4 "/>
  </config>


  $ xmllint example.xml --xpath "/config/*/@*"

The result is:

   key1="value1 " key2=" value2" key3="value3" key4=" value4 "

What I'd like to get is:

   key1="value1 "
   key2=" value2"
   key3="value3"
   key4=" value4 "

Would I need to split after even-numbered quote marks, or is there any neater way to do this?

There's a related question, about the same subject except it's about picking out contents of <tag>value</tag>, and not <tag attribute="value" />

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can try:

$ xmllint --shell inputfile <<< 'cat /config/*/@*'

You might need to grep the output, though, so as to filter the undesired lines.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...