reading and searching xml element text in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reading and searching xml element text in script
# 1  
Old 11-24-2005
Java 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 inside the xml without using java. The underlined part is the directory... so the script will first look into the tag--filecopy..then look into a basedirectory which i created called checkdirectory after that it will look into /new/test/ in the tag which is also a directory to locate the file.

Eg. thefile.txt is in checkdir/new/test/thefile.txt
and thefile2 is in checkdir/new/thefile2.txt

i have a code here....but it will only capture file in the tag...it will not look into /new/test folder...can someone help me out?

the coding i have is :
#!/bin/sh

sed -e '/filecopy/ !d' -e 's!<filecopy>\([^<]*\)</filecopy>!\1!' filereader.xml | while read file; do
if [ -f "../checkdir/${file}" ]; then
echo "File exists : ${file}"
else
echo "File not exist : $${file}"
fi
done

exit 0

Last edited by forevercalz; 11-24-2005 at 09:37 PM..
# 2  
Old 11-24-2005
Where are you running the script from? I can't see anything wrong with it as it stands.

Is that supposed to be two full-stops in the file-test? If you're running it from the directory containing checkdir, then it should be one.

Cheers
# 3  
Old 11-24-2005
Well..i manage to solve the problems now...
by doing this

sed -e '/filecopy/ !d' -e 's!<filecopy>\([^<]*\)</filecopy>!\1!' filereader.xml | while read file; do
file_dir=$checkdir/${file}
if [ -f "$file_dir" ]; then
echo "File exists : $file_dir"
else
echo "File not exist : $file_dir"
fi
done

Last edited by forevercalz; 11-24-2005 at 10:12 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

How to write in other language in text/xml file by reading english text/xml file using C++?

Hello Team, I have 2 files.one contains english text and another contains Japanese. so i have to read english text and replace the text with Japanesh text in third file. Basically, I need a help to write japanese language in text/xml file.I heard wstring does this.Not sure how do i write... (2 Replies)
Discussion started by: SA_Palani
2 Replies

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

3. Shell Programming and Scripting

Reading xml tags from ksh script

Hi, I have an XMl file, below is sample: <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... (6 Replies)
Discussion started by: kedar_laveti
6 Replies

4. Shell Programming and Scripting

Find if XML element has a matching required element

I want to check if every <Part> element has corresponding <Description> in this sample XML. ....<Lot Of XML> <Inv lineNumber="2"> <Item> ... (4 Replies)
Discussion started by: kchinnam
4 Replies

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

6. UNIX Desktop Questions & Answers

read XML xml element with REGEXP

Hi, I would need to read an xml element from an xml file to a local variable. Please could you help me with a shell script to get so? Considering that I have a file called file.xml like below: <header> <description>This is the description</description> <content>This is the... (2 Replies)
Discussion started by: oscarmon
2 Replies

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

8. Shell Programming and Scripting

Searching XML tag in a script

Hey, I need to parse the following XML to just grab the Customer ID. Is there any RegEx that can achieve this ? So in this example, the script just return 0000109654, as the output. Even if it involves awk, sed please let me know. ************ <?xml version="1.0" encoding="UTF-8"?>... (1 Reply)
Discussion started by: abhandari
1 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