How to Parse the XML data along with the URL in Shell Script?

Hi,

Can anybody help to solve this. I want to parse some xmldata along with the URL in the Shell.

I'm calling the URL via the curl command

Given below is my shell script file

export url="http://localhost/test/apirequest.php?&apikey=Zm9ybSRAMCMjMjAxMy0wMS0wMyAxNDo0MjoyNg==&reqtype=xml&operation=insertRecords&xmldata=<?xml"\ "version="1.0" encoding="iso-8859-1"?><root><FORM name ="Form1"><row no="0"><FL val="Company">New Company2</FL></row></FORM></root>"

script=$(curl -s "$url")
printf "%s\nDo you want to run this script? [yN]" "$script"
read line
case $line in
[Yy]|[Yy][Ee][Ss])
 sh <<EOF
 $script
EOF
esac

Thanks in Advance

What is the problem with this script??

The script goal is to �?
As far as I get, your script stores into a variable "script" the result of the curl execution "curl -s "$url" "and then executes that result.+

So, what error do you get?
Is that the purpose of your script?
Can you tell what is the return value of the curl execution?

Regards.

Do you mean you want to parse the data you receive back from curl?
If so, Post some sample data.:confused:

The Exact prob here is the URL which i parse is getting breaked due to the space in it.

Example:

myurl="http://localhost/test/apirequest.php?&apikey=Zm9ybSRAMCMjMjAxMy0wMS0wMyAxNDo0MjoyNg==&reqtype=xml&operation=insertRecords&xmldata=<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><root><FORM name=\"Form1\"><row no=\"0\"><FL val=\"Company\">NewCompany2</FL></row></FORM></root>"

Here the url is getting breaked due the space between the strings xml version .And the same prob happens , whevener there is same some in between the strings.

Please do help me soon:(:frowning:

Threads merged..

Why not enclose string with single quotes so the shell will supply string exactly as you specify?, Example of both ways:

$ cat test.sh
url="http://localhost/test/apirequest.php?&apikey=Zm9ybSRAMCMjMjAxMy0wMS0wMyAxNDo0MjoyNg==&reqtype=xml&operation=insertRecords&xmldata=<?xml"\ "version="1.0" encoding="iso-8859-1"?><root><FORM name ="Form1"><row no="0"><FL val="Company">New Company2</FL></row></FORM></root>"
echo $url
url='http://localhost/test/apirequest.php?&apikey=Zm9ybSRAMCMjMjAxMy0wMS0wMyAxNDo0MjoyNg==&reqtype=xml&operation=insertRecords&xmldata=<?xml"\ "version="1.0" encoding="iso-8859-1"?><root><FORM name ="Form1"><row no="0"><FL val="Company">New Company2</FL></row></FORM></root>'
echo $url


$ test.sh
http://localhost/test/apirequest.php?&apikey=Zm9ybSRAMCMjMjAxMy0wMS0wMyAxNDo0MjoyNg==&reqtype=xml&operation=insertRecords&xmldata=<?xml version=1.0 encoding=iso-8859-1?><root><FORM name =Form1><row no=0><FL val=Company>New Company2</FL></row></FORM></root>
http://localhost/test/apirequest.php?&apikey=Zm9ybSRAMCMjMjAxMy0wMS0wMyAxNDo0MjoyNg==&reqtype=xml&operation=insertRecords&xmldata=<?xml"\ "version="1.0" encoding="iso-8859-1"?><root><FORM name ="Form1"><row no="0"><FL val="Company">New Company2</FL></row></FORM></root>

Hey Thanks :slight_smile: But still i'm facing the Issues. :frowning:

curl function doesn't supports the url with spaces in it.

curl -s "$url"

So i'm switching to java and i achieved this.

---------- Post updated at 04:44 PM ---------- Previous update was at 11:28 AM ----------

Hey all i resolved It.:b:

i replaced all the Spaces and special characters in the url with the encoded values

eg. space = "%20"
double quotes = "%22"
greater than symbol = "%3C"
lesser than symbol = "%3E"

url ="http://localhost/test/apirequest.php?&apikey=Zm9ybSRAMCMjMjAxMy0wMS0xMCAxMDowNTozNw==&reqtype=xml&operation=insertRecords&xmldata=%3C?xml%20version=%221.0%22%20encoding=%22iso-8859-1%22?%3E%3Croot%3E%3CFORM%20name%20=%22Lead%22%3E%3Crow%20no=%220%22%3E%3CFL%20val=%22Company%22%3ENew%20Company54543%3C/FL%3E%3CFL%20val=%22First%20Name%22%3ESuresh%3C/FL%3E%3CFL%20val=%22Last%20Name%22%3EKarthiKeyan%3C/FL%3E%3CFL%20val=%22Mobile%22%3E9600081288%3C/FL%3E%3CFL%20val=%22Email%22%3E%3C/FL%3E%3CFL%20val=%22Status%22%3EConverted%3C/FL%3E%3CFL%20val=%22Assigned%20To%22%3Esadmin%3C/FL%3E%20%3C/row%3E%3C/FORM%3E%3C/root%3E"

Thanks for your replies. ::):slight_smile: