Solved

xmllint on solaris

Posted on 2013-05-31
4
1,039 Views
Last Modified: 2013-05-31
greetings, I am trying to grab a value out of an xml node using XMLLINT.  my problem is that in Solaris 10, xmllint --xpath option does not exist.  I am not allowed to upgrade libxml to get that option.

To that end, I'm doing the cat function to get the value I'm looking for.

I'm trying the example in: http://stackoverflow.com/questions/11611385/get-value-from-an-attribute-using-xmllint

test=$(echo 'cat //body/value/@name' | xmllint --shell "test.xml" | grep -v ">" | cut -f 2 -d "=" | tr -d \");
echo $test

my call is:
test = $(echo 'cat //*[local-name()='document']/*[local-name()='code']/@code' | xmllint --shell "af176493-5b64-4dcc-bd1a-e01517146737.xml" | grep -v ">" | cut -f 2 -d "=" | tr -d \");
echo$test

now, if I manually go into xmllint --shell "af176493-5b64-4dcc-bd1a-e01517146737.xml"
and run: cat //*[local-name()='document']/*[local-name()='code']/@code

I get my value...no problem.

But if I put it in the script as the call, I get no value.
help?  Thanks.
0
Comment
Question by:Evan Cutler
  • 2
  • 2
4 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39210675
I don't know much abour xmllint, but these spaces around " = " are wrong:

Correct syntax:

Test=$(echo 'cat .. ...
...
echo $Test


Please note the uppercase "T"in "Test". "test" is a shell builtin, you should not use this name for variables in order to avoid confusion.
0
 
LVL 9

Author Comment

by:Evan Cutler
ID: 39210680
thanks...I get that...i was manually typing that in.  I need an xmllint guy.  

if I run this in a prompt:
echo 'cat //*[local-name()='document']/*[local-name()='code']/@code' | xmllint --shell "af176493-5b64-4dcc-bd1a-e01517146737.xml" | grep -v ">" | cut -f 2 -d "=" | tr -d \"

it returns nothing.

but if I do it in a shell...it returns my value.
THanks.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39210704
The single quotes around 'document' and 'code' might be a problem since the whole command is also surrounded by single quotes.

Try double quotes:

Test=$(echo "cat //*[local-name()='document']/*[local-name()='code']/@code" | xmllint ...
0
 
LVL 9

Author Closing Comment

by:Evan Cutler
ID: 39210713
He Shoots, He Scores!!!
Thanks very much.  That was it.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now