Reading xml tags from ksh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading xml tags from ksh script
# 1  
Old 03-27-2013
Reading xml tags from ksh script

Hi,

I have an XMl file, below is sample:
Code:
<TRANSFORMATION DESCRIPTION ="Created by:- " NAME ="LKP_FT_T_FILEK" OBJECTVERSION ="1" REUSABLE ="YES" TYPE ="Lookup Procedure" VERSIONNUMBER ="1">
</TRANSFORMATION>

I need to read the tag, and if the tag is TRANSORMATION, i want to check the Type and then the name.

The basic requirement is to check the naming standards

Can anyone please help?

Thanks
# 2  
Old 03-27-2013
Code:
OLDIFS="$IFS"
IFS="\"="
while read LINE
do
        [[ "$LINE" == *"<TRANSFORMATION"* ]] || continue

        set -- $LINE

        while [ "$#" -gt 0 ]
        do
                case "$1" in
                *NAME*)
                        echo "Got name $2"
                        shift
                        ;;
                esac
                shift
        done
done

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 03-28-2013
How do we take the input file in the above and How to capture the xml tag attribute value into variable in shell script??
# 4  
Old 03-28-2013
Have you tried the code I gave above? It splits and searches in tags, and uses case statements to tell which are which, you can alter it a little to do exactly what you want.
# 5  
Old 03-29-2013
Hi Corona,

Thank you so much, the code was very helpful.
set-- is printing the attributes of the tag, is it possible to put the result of set-- into a variable?

Or is it possible to display the result of set-- $LINE in : delimited format?

Thank you

Last edited by kedar_laveti; 03-29-2013 at 09:40 AM..
# 6  
Old 03-29-2013
Quote:
Originally Posted by kedar_laveti
. . .
set-- is printing the attributes of the tag,
It is not. It sets the positional parameters $1 ... $n to the elements of $LINE.

Quote:
is it possible to put the result of set-- into a variable?
What about e.g. VARIABLE=$2?
This User Gave Thanks to RudiC For This Post:
# 7  
Old 04-03-2013
Thanks Corona and Rudi,

Your suggestions helped me a lot. I got the idea to read the xml tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

2. Shell Programming and Scripting

Replacing number between xml tags with ksh shell script

Hallo, im basically a complete noob on shell scripting and im trying to replace or rather add 1 to a number between xml tags. The xml basically has a tag somewhere that looks like this: <tag>12345678901234</tag> Now i want to replace the number between the tags. And i want the file to... (6 Replies)
Discussion started by: Demoric
6 Replies

3. Shell Programming and Scripting

Change values in Log4j.xml using ksh script

Hi, I am new to UNIX and shell scripting. I have to create a shell script(ksh) which parses log4j.xml file for a given webservice name and change the corresponding value from INFO to DEBUG or vice-versa. My log4j.xml looks like:- <!-- Appender WEBSERVICENAME--> <appender... (3 Replies)
Discussion started by: sanjeevcseng
3 Replies

4. Shell Programming and Scripting

reading xml attributes with shell script

Hi, Iam new to shell scripting.I have below urgent requirement I want to read attributes (transaction,documentmode) in xml tag with shell scripting and create a filename with these attribues Xml : <PURCHASE_10 partner="food" version="1.50" timestamp="2009-03-10T09:56:55"... (3 Replies)
Discussion started by: swetha123
3 Replies

5. Shell Programming and Scripting

KSH Script to Get the <TAG Values> from an XML file

Hi All, I am new to Unix I need a KSH script to get the values from XML file to write to a temp file. Like the requirement is from the below TAG <MAPPING DESCRIPTION ="Test Mapping" ISVALID ="YES" NAME ="m_test_xml" OBJECTVERSION ="1" VERSIONNUMBER ="1"> I need the MAPPING DESCRIPTION... (3 Replies)
Discussion started by: perlamohan
3 Replies

6. Shell Programming and Scripting

reading XML datas via Shell Script

Hi all, i have an xml file with this fomat(exactly) : <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE TestSuite SYSTEM "../../CallCrt.dtd"> <TestSuite description="Diameter"> <FileReference FileName="DMI_FC01.xml"/> <!--<FileReference FileName="DMI_FC02.xml"/> -->... (1 Reply)
Discussion started by: freepal
1 Replies

7. 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

8. Shell Programming and Scripting

reading and searching xml element text in script

well i have this xml file here: this file is called filereader.xml <?xml version="1.0" encoding="UTF-8"?> <file> <file1> <filecopy>/new/test/thefile.txt</filecopy> <filecopy>/new/test/thefile2.ppt</filecopy> </file1> </file> i need to write the script that search for the Bold text... (2 Replies)
Discussion started by: forevercalz
2 Replies

9. Shell Programming and Scripting

reading and searching xml element text in script

well i have this xml file here: this file is called filereader.xml <?xml version="1.0" encoding="UTF-8"?> <file> <file1> <filecopy>thefile.txt</filecopy> <filecopy>thefile2.ppt</filecopy> </file1> </file> hi..i got this problem....hmm how do i write a... (6 Replies)
Discussion started by: forevercalz
6 Replies
Login or Register to Ask a Question