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-10-2005
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 script to read this xml file? and how do i write the script that search for the Bold text inside the xml without using java.
# 2  
Old 11-10-2005
Code:
sed -e '/filecopy/ !d' -e 's!<filecopy>\([^<]*\)</filecopy>!\1!' foo.xml

Cheers
ZB
# 3  
Old 11-10-2005
well as im doing this in a script..how do i write this out...
#!/bin/sh
..
..
#i wrote this:
echo `sed -e '/filecopy/ !d' -e 's!<filecopy>\([^<]*\)</filecopy>!\1!' filereader.xml`

and when i run the script..it says cannot open filereader.xml.However if i paste this in the command itself without using script...i can get the output. what happen?
# 4  
Old 11-10-2005
Quote:
Originally Posted by forevercalz
well as im doing this in a script..how do i write this out...
#!/bin/sh
..
..
#i wrote this:
echo `sed -e '/filecopy/ !d' -e 's!<filecopy>\([^<]*\)</filecopy>!\1!' filereader.xml`
No need for the echo and backticks....

Just do

Code:
#!/bin/sh

sed -e '/filecopy/ !d' -e 's!<filecopy>\([^<]*\)</filecopy>!\1!' filereader.xml

exit 0

Then if that doesn't work check the path to the file.

Cheers
ZB
# 5  
Old 11-10-2005
thanks! however after i get this out..
thefile.txt
thefile2.ppt
the script will need to check whether this file exist inside the directory..the directory is call ../checkdir. Usually the files will exist in the directory and it will echo file exist. hmm..any idea on this?
# 6  
Old 11-10-2005
Code:
#!/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"
  fi
done

exit 0

Cheers
ZB
# 7  
Old 11-10-2005
Wow! thanks thanks alot...zazzybob! cheerrsss...:P:P:P
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>/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
Login or Register to Ask a Question