Answer the question
In order to leave comments, you need to log in
Outputting the contents of an xml element on the command line?
Good day to all.
The point is the following. There is a certain xml-document of the following form (source document here ):
Task. Print the contents of an element (for example, the productKey element ) in text form using the xmlstarlet utility on the command line (originally windows, but the command syntax of the linux version of xmlstarlet is the same).
I read the documentation , googled this topic. However, I did not find an explicit answer.
Interested in the final form of the command:
Microsoft Windows [Version 6.1.7601]
© 2009 Microsoft Corporation. All rights reserved.
C:\Users\User\Desktop\XML> xml.exe sel ??? document.xml
A1B2C3D4
Answer the question
In order to leave comments, you need to log in
And you have xmlns there, so xmlstarlet “does not see” the tag inside. So just like this:
$ xmlstarlet sel -t -v "//*[name()='productKey']" document.xml
If the element you are looking for has no prefix, i.e. belongs to xmlns - default namespace, then "_" can be substituted for such elements instead of the namespace prefix
The parser has, by the way, a useful option -D, which shows the generated XSLT code with which it is going to receive data.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question