简体   繁体   中英

Using xmlstarlet to select from XML - syntax query

I have an XML file which I'm trying to transform into something more like CSV format (well some format which puts the output on a single line with a common delimiter), but I can't quite get the syntax right, can anyone help please? The XML looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<TranslationTable>
        <Translation Key="Document1" RelativePath="/home/path1">
                <Title>Doc1</Title>
                <Description>First document</Description>
        </Translation>
        <Translation Key="Document2" RelativePath="/home/path2">
                <Title>Doc2</Title>
                <Description>Second document</Description>
        </Translation>
</TranslationTable>

And my command at present is this

xmlstarlet sel -t -m //Translation -v @Key -o "|" -v @RelativePath -n /root/XML/file.xml
Document1|/home/path1
Document2|/home/path2

But what I'd like is to also include the contents of the Title field, so that the output is like this

Document1|/home/path1|Doc1
Document2|/home/path2|Doc2

Can anyone help please? Thanks.

这是XPath

xmlstarlet sel -t -m //Translation -v @Key -o "|" -v @RelativePath  -v 'Title/text()' -n /root/XML/file.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM