1

I am dealing with datasets on xml files; which have the following structure:

<?xml version="1.0" standalone="yes"?>
<exper>
  <entry>
    <Source />
    <Status>pass</Status>
    <Title>S2</Title>
  </entry>
  <entry>
    <Source />
    <Status>fail</Status>
    <Title>S1</Title>
  </entry>
  <entry>
    <Source />
    <Status>pass</Status>
    <Title>S3</Title>
  </entry>

I could parse this in Python and get done with it; but is there anything that can be done on the fly, maybe using some sort of visual editor, to get only a list of the title tag? for each entry?

I am using Notepad on Windows to read the file, which is not the best way to go for sure. I also have miniGW, so I could run AWK maybe; although I was told that parsing XML files is not ideal for neither SED nor AWK.

2
  • are you able to install xmlstarlet tool/package? Dec 9 '17 at 22:10
  • Yes, I did search for it and found the download. Is it easy to use? Never heard of it
    – rataplan
    Dec 9 '17 at 22:16
1

1) Install xmlstarlet https://sourceforge.net/projects/xmlstar/files/xmlstarlet/1.6.1/

2) Process XML documents from command line:

xmlstarlet sel -t -v "//Title" -n input.xml

The output:

S2
S1
S3
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.