XML file parsing using script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting XML file parsing using script
# 1  
Old 09-28-2009
XML file parsing using script

Hi
I need some help with XML file parsing. I have an XML file with the below tag,
I need a script to identify the value of srvcName which is this case is "AAA srvc name". I need to put contents of this value which is AAA srvc and name into different variables using an array and then reformat it and put it into a different variable, in this case lets say RESULT. RESULT should look like "AAA\ srvc\ name"

Code:
<platform type="windows" startMenuName="AAA" startMenu="BBB.ico"  addRemoveName="AAA" addRemoveIcon="BBB.ico"
srvcName="AAA srvc name"
 />

What I am trying to do is to retrieve values from a source XML file and write the contents of the value into a target XML file using a shell script. In the target XML file I want to replace lets say a value XXX with "AAA srvc name". Thanks.
# 2  
Old 09-28-2009
what shell?
what did you try so far?
# 3  
Old 09-29-2009
sh or bash. I have attempted to search and retrieve the contents of the string. I need some leads in what I can use to split the string, put it into an array and reformat it. Thx
# 4  
Old 09-30-2009
I'd use sed:
Code:
var=$(sed -n 's/srvcName="\([^"]*\)"/\1/p' source.xml)
sed 's/srvcName="XXX"/srvcName="'"$var"'"/' target.xml

# 5  
Old 09-30-2009
you can use perl module XML::Reader.
# 6  
Old 09-30-2009
So if I do this I do not need to split the string? Using this method does it replacing the target with the string (with spaces), can you explain the sed command? Thanks.
# 7  
Old 10-12-2009
var=$(sed -n 's/srvcName="\([^"]*\)"/\1/p' source.xml)


I have changed the above command to the below to get thsi working.

var=`sed -n 's/serviceName="\([^"]*\)"/\1/p' name.xml`

I am running into the below error while trying the command you posted
./test.sh: syntax error at line 98: `var=$' unexpected

Also can someone explain the command
var=`sed -n 's/serviceName="\([^"]*\)"/\1/p' name.xml`

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with parsing xml file

Hi, Need help with parsing xml data in unix and place it in a csv file. My xml file looks like this: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <iwgroups> <nextid value="128"> </nextid> <iwgroup name="RXapproval" id="124" display-name="RXapproval"... (11 Replies)
Discussion started by: ajayakunuri
11 Replies

2. UNIX for Dummies Questions & Answers

Parsing XML file

I want to parse xml file sample file....... <name locale="en">my_name<>/name><lastChanged>somedate</lastChanged><some more code here> <name locale="en">tablename1<>/name><lastChanged>somedate</lastChanged> <definition><dbquery><sources><sql type="cognos">select * from... (10 Replies)
Discussion started by: ms2001
10 Replies

3. Shell Programming and Scripting

XML: parsing of the Google contacts XML file

I am trying to parse the XML Google contact file using tools like xmllint and I even dived into the XSL Style Sheets using xsltproc but I get nowhere. I can not supply any sample file as it contains private data but you can download your own contacts using this script: #!/bin/sh # imports... (9 Replies)
Discussion started by: ripat
9 Replies

4. Shell Programming and Scripting

Parsing XML using shell script

Well, issue is i have to parse this script to get the VERSION: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleAllowMixedLocalizations</key> ... (9 Replies)
Discussion started by: zorosinister
9 Replies

5. Shell Programming and Scripting

XML parsing using shell script

I have a xml file like this <bul:collectionStrategy name="strategy1"> <bul:collectionTemplateGroup name="15min group"/> <bul:collectionTemplateGroup name="hourly group"/> </bul:collectionStrategy> <bul:CollectionTemplateGroup name="hourly group" > ... (2 Replies)
Discussion started by: LavanyaP
2 Replies

6. Shell Programming and Scripting

XML parsing in a shell script.

Below is a XML I have... <?xml version="1.0" encoding="UTF-8" ?> <component xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:XXXXX-www-Install-Manifest manifest.xsd" xmlns="urn:qqqqq-Install-Manifest" name="OM" ... (1 Reply)
Discussion started by: dashok.83
1 Replies

7. Shell Programming and Scripting

Parsing xml file

hi guys, great help to the original question, can i expand please? i have large files filled with blocks like this <Placemark> network type: hot line1 line2 line3 <styleUrl>red.png</styleUrl> </Placemark> <Placemark> network type: cold line1 line2 line3... (3 Replies)
Discussion started by: garvald
3 Replies

8. UNIX for Dummies Questions & Answers

Help parsing a XML file ....

Well I have read several threads on the subject ... but being a newbie like me makes it hard to understand ... What I need is the following: Input data: ------- snip --------- <FavouriteLocations> <FavouriteLocations class="FavouriteList"><Item... (6 Replies)
Discussion started by: misak
6 Replies

9. Shell Programming and Scripting

Parsing XML using Shell Script

Hello, I'm a starting shell scripter and no Perl knowledge. I've trying to do this for a while: I want to parse an XML file and get certain data out of it and write that data into a CSV file, all this using Shell Scripting (in Bash). Or Perl without any XML Parser/Interpreter (if possible). ... (1 Reply)
Discussion started by: Kage Musha
1 Replies

10. Shell Programming and Scripting

Parsing and getting data from XML file using ksh script

Hi All, I have a xml file for example as described below <xml> <address> <street><street> <address/> <isbn>426728783932020308393930303</isbn> <book> <name> </name> </book> . . . </xml> My problem is to get the isbn number from the above described file using ksh script. Could... (6 Replies)
Discussion started by: vinna
6 Replies
Login or Register to Ask a Question