how to use xmllint in order to get value from xml

I have the following XML file

<?xml version="1.0" encoding="UTF-8" ?> <!-- Component configuration file --> <Component> <Name>install_env</Name> <HelpString>install_env Com</HelpString> <Version>1.10.3</Version> <Properties> 

how to get the value of Name tag - install_env

by using the tool - xmllint

1 Answer

With your testfile:

<?xml version="1.0" encoding="UTF-8" ?> <!-- Component configuration file --> <Component> <Name>install_env</Name> <HelpString>install_env Com</HelpString> <Version>1.10.3</Version> </Component> 

I use --xpath argument to get the value of the name tag:

user$ test=$(xmllint --xpath "//Component/Name/text()" testfile) user$ echo $test install_env 

--xpath implies --noout, which prevents xmllint from outputting anything. Redirect the output to a variable or a file.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like