W
W
winntpooh2012-12-02 20:56:17
Parsing
winntpooh, 2012-12-02 20:56:17

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 ):
f378f3d6e07c1ffd50aca6be3185a5e7.png
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

I believe that this task is solved by xmlstarlet using XPath, but any other methods will do.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Antelle, 2012-12-02
@winntpooh

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

C
cat_crash, 2012-12-02
@cat_crash

Why not use xsltproc + xslt file?

D
Dima, 2017-08-09
@v_m_smith

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 question

Ask a Question

731 491 924 answers to any question