How to get Xmllint to read from stdin?

Xmllint

Xmllint Problem Overview


  • I don't want to create an XML file

  • I need to use the --shell with cat to create filters

  • I don't have xpath in my version of xmllint, using libxml2-2.7.6-14.el6.x86_64

    xml|xmllint --shell - <<< $(echo 'cat /')

    -:1: parser error : Start tag expected, '<' not found

EDIT: clustat -x outputs an XML file and I want to parse out the active node. I don't think there is a way to do it without xpath so I created a temp xml file.

/usr/sbin/clustat -x > /tmp/clustat.xml
ACTIVENODE=$(xmllint --shell /tmp/clustat.xml <<< `echo 'cat //group/@owner'`|grep -v "^/ >"|cut -d= -f2|tr -d \")

Xmllint Solutions


Solution 1 - Xmllint

I had a similar issue where I had to unzip an XML file then feed it to xmllint. The key is the "-" option which tells xmllint to read from stdin.

For example:

$ bzip2 -dc dierehabilitati00delagoog_meta.xml.bz2 | xmllint --format

would fail giving the "usage" for xmllint. Adding "-" worked:

$ bzip2 -dc dierehabilitati00delagoog_meta.xml.bz2 | xmllint --format -
<?xml version="1.0"?>
<metadata>
  <title>Die Rehabilitation im Strafrecht</title>
  <creator>Ernst Delaquis</creator>
  <mediatype>texts</mediatype>
  <collection>americana</collection>
</metadata>

Hope this helps.

Categories

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDejanView Question on Stackoverflow
Solution 1 - XmllintaiGuruView Answer on Stackoverflow