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 attribute My example was probably not clear enough and misleading. I'll try with another example: example.xml: <?xml version="1.0"?> <rdf:RDF xmlns:ns="#" xmlns:rdf="#" > <ns:n rdf:a="this is a very very very very very very long string">text</ns:n> </rdf:RDF> 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 example.xml 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 xmllint? Gökçe
smime.p7s
Description: S/MIME Cryptographic Signature
_______________________________________________ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org https://mail.gnome.org/mailman/listinfo/xml