5 thoughts on “extract xml from the command line

  1. egravers

    sed -n 3p
    did not work for me
    sed -n 2p
    did work!

    …or use sed to delete the lines with the “/ > ” prompt?

    sed ‘/^\/ >/ d’

  2. Pingback: Laurent Schneider » xml and powershell

  3. Laurent Schneider Post author

    you use /@attr
    $ echo 'cat //emplist/emp[@no="1"]/@no'|
    xmllint --shell foo.xml |grep '"'|
    cut -d'"' -f2
    1

    and to get the attribute name, use dir

    $ echo 'dir //emplist/emp[1]'|
    xmllint --shell foo.xml|
    awk '$1=="ATTRIBUTE"{print $2}'
    no

Comments are closed.