Visit Our UNIX and Linux User Community


To read a flat file containing XML data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To read a flat file containing XML data
# 1  
Old 07-21-2011
To read a flat file containing XML data

I have a file something like this:aaaa.xml content of the file is


Code:
0,<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<storeInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<s> 
<BRANCH_NO>3061</BRANCH_NO> 
<BRANCH_NAME>GREEN EXPRESS</BRANCH_NAME> 
<STORE_TYPE>Superstore</STORE_TYPE> 
</s> 
</storeInformation>,<?xml version="1.0" encoding="UTF-8" standalone="yes"?><storeInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <s><BRANCH_NO>3061</BRANCH_NO><BRANCH_NAME>GREEN EXPRESS</BRANCH_NAME>NE><STORE_TYPE>Superstore</STORE_TYPE></s></storeInformation> 
1,<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<storeInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<s> 
<BRANCH_NO>3062</BRANCH_NO> 
<BRANCH_NAME>GREEN EXPRESS</BRANCH_NAME> 
<STORE_TYPE>Superstore</STORE_TYPE> 
</s> 
</storeInformation>,<?xml version="1.0" encoding="UTF-8" standalone="yes"?><storeInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <s><BRANCH_NO>3062</BRANCH_NO><BRANCH_NAME>GREEN EXPRESS</BRANCH_NAME><STORE_TYPE>Superstore</STORE_TYPE></s></storeInformation>


My requirement is i need to read the file line by line and write to two files

Output:
The first file should have this content

file1.xml

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<storeInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<s> 
<BRANCH_NO>3061</BRANCH_NO> 
<BRANCH_NAME>GREEN EXPRESS</BRANCH_NAME> 
<STORE_TYPE>Superstore</STORE_TYPE> 
</s> 
</storeInformation>


The second file should have this content file2.xml


Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><storeInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <s><BRANCH_NO>3061</BRANCH_NO><BRANCH_NAME>GREEN EXPRESS</BRANCH_NAME><STORE_TYPE>Superstore</STORE_TYPE></s></storeInformation>


file1 and file2 will be processed .After processing, I need to read the second line of aaaa.xml and write it in the same file1.xml and file2.xml

In the same way i need to process the entire file line by line.

Could you please help me in resolving this issue?


Thanks
Krishnakanth Manivannan

Last edited by radoulov; 07-21-2011 at 11:16 AM.. Reason: Code tags, please!
# 2  
Old 07-21-2011
Read this xml to csv and xml to data first. Include basic methods to convert xml into more flat version.

"Print version".

Last edited by kshji; 07-21-2011 at 04:59 PM..
# 3  
Old 07-21-2011
Sorry Sir.. I am getting junk characters from this link.

is it due to browser error?

krishnakanth
# 4  
Old 07-21-2011
Quote:
Originally Posted by kmanivan82
Sorry Sir.. I am getting junk characters from this link.

is it due to browser error?

krishnakanth
????
# 5  
Old 07-22-2011
We have gone through the link. it is not helpful for us.

I am not sure whether the commands mentioned in the link are unix commands.

We have to perform this using Unix commands(shell script).

could you please help me on that!!


Krishnakanth Manivannan

Previous Thread | Next Thread
Test Your Knowledge in Computers #146
Difficulty: Easy
In 1983, Richard Stallman announced the GNU (short for "GNU's Not Unix") project, to create a proprietary, commercial software Unix-like system.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

XML Parsing having optional tags into flat file

In xml file i have following data where some tags like<ChrgBr> may not be present in every next file. So i want these values to be stored in some variable like var1="405360,00" , var2="DEBT" and so on ,but if <ChrgBr> tag has no value or is absent var2 should have space like var2=" " so that i... (1 Reply)
Discussion started by: sandipgawale
1 Replies

2. Shell Programming and Scripting

[ask]xml to flat file

dear all, i need your advice, i have xml file like this input.xml <?xml version="1.0" encoding="UTF-8"?> <session xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> <capture> <atribut name="tmp_Filename" value="INTest.rbs"/> <atribut name="size_Filename" value="INTest.rbs"/>... (2 Replies)
Discussion started by: zvtral
2 Replies

3. Shell Programming and Scripting

Help with converting XML to Flat file

Hi Friends, I want to convert a XML file to flat file. Sample I/p: <?xml version='1.0' encoding='UTF-8' ?> <DataFile xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' contactCount='4999' date='2012-04-14' time='22:00:14' xsi:noNamespaceSchemaLocation='gen .xsd'> <Contact... (3 Replies)
Discussion started by: karumudi7
3 Replies

4. Shell Programming and Scripting

Reading XML data in a FLAT FILE

I have a requirement to read the xml file and split the files into two diffrent files in Unix shell script. Could anyone please help me out with this requirement. Sample file --------------- 0,<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Information... (3 Replies)
Discussion started by: kmanivan82
3 Replies

5. Shell Programming and Scripting

Converting a flat file in XML

Hello Friends, I am new to UNIX shell scripting. Using bash....Could you please help me in converting a flat file into an XML style output file. Flat file: (Input File entries looks like this) John Miller: 617-569-7996:15 Bunting lane, staten Island, NY: 10/21/79: 60600 The... (4 Replies)
Discussion started by: humkhn
4 Replies

6. Shell Programming and Scripting

Read data in XML file

Hello Everybody, I have a question on reading the data from XML file through KSH shell script. In the below file I need to collect the patient control no and its respective insured id. I need to have pair of these values in single line separated by some special character, so that I could use... (2 Replies)
Discussion started by: swame_sp
2 Replies

7. Programming

compare XML/flat file with UNIX file system structure

Before i start doing something, I wanted to know whether the approach to compare XML file with UNIX file system structure. I have a pre-configured file(contains a list of paths to executables) and i need to check against the UNIX directory structure. what are the various approches should i use ? I... (6 Replies)
Discussion started by: shafi2all
6 Replies

8. Shell Programming and Scripting

XML to flat file

Hi all, can u please help me in converting any given XML file to flat file. thanks in advance. -bali (2 Replies)
Discussion started by: balireddy_77
2 Replies

9. UNIX for Advanced & Expert Users

XML to flat file in Unix

Hello, How can I take a file in XML format and convert it to a comma separated format? Is there any scripts or programs that can do this for Unix? I tried surfing the net for such an application, but everything seems to be for Windows OS. Any help or suggestions are greatly appreciated. ... (2 Replies)
Discussion started by: oscarr
2 Replies

Featured Tech Videos