Re: [xml] getting the output of string() in the xmllint shell

On 2019-12-21 09:28, Daniel Veillard wrote:
On Fri, Dec 20, 2019 at 12:46:23PM +0100, Gökçe Aydos wrote:
I use xmllint in my command-line scripts. The default mode of xmllint
does not support namespaces, so when I must deal with XML files with
namespaces I use the --shell mode of xmllint.

  That sounds ... wrong

Is xmllint not meant for using as a command-line tool? Can you please
elaborate on your answer?

  your request is very confusing but you should be able to get the string
value of the attributes directly by using an XPath looking for that

My example was probably not clear enough and misleading. I'll try with
another example:


  <?xml version="1.0"?>
  <ns:n rdf:a="this is a very very very very very very long

To extract the value of the rdf:a attribute, I would use:

  xmllint --xpath 'string(//ns:n/@rdf:a)' example.xml

But this errors out, because the plain xmllint does not support namespaces:

  XPath error : Undefined namespace prefix
  XPath evaluation failure

That is the reason why I use the shell mode:

  echo -e "setrootns\nxpath string(//ns:n/@rdf:a)" | xmllint --shell

The result is truncated and not clean:

  / > / > Object is a string : this is a very very very very very very ...
  / >

Does someone have a better idea on how to get attribute values using


Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]