Need to split a xml file in proper format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to split a xml file in proper format
# 1  
Old 08-19-2011
Java Need to split a xml file in proper format

Hi,

I have a file which has xml data but all in single line
Ex -
Code:
<?xml version="1.0"?><User><Name>Robert</Name><Location>California</Location><Occupation>Programmer</Occupation></User>

I want to split the data in proper xml format Ex-
Code:
<?xml version="1.0"?>
<User>
<Name>Robert</Name>
<Location>California</Location>
<Occupation>Programmer</Occupation>
</User>

Can anybody help me with the issue.

Regards
Avishek Khan

Last edited by Franklin52; 08-19-2011 at 03:12 PM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 08-19-2011
Code:
$ sed 's,><,>\\n<,g;s,^,echo \",g;s,$,\",g' inputfile | sh

# 3  
Old 08-19-2011
Thanks for your reply,
but one issue:
if a tag contains null values that is also splitted into new line see the tag Phone
Ex
Code:
<?xml version="1.0"?>
<User>
<Name>Robert</Name>
<Location>California</Location>
<Occupation>Programmer</Occupation>
<Phone>
</Phone>
</User>


Last edited by Franklin52; 08-19-2011 at 03:13 PM.. Reason: Please use code tags for data and code samples, thank you
# 4  
Old 08-19-2011
try this ..
Code:
$ sed 's,></,>null</,g;s,><,>\\n<,g;s,^,echo \",g;s,$,\",g;s,null,,g;s,></User,>\\n</User,g' inputfile | sh

# 5  
Old 08-19-2011
Hi,
Try this

Code:
 sed 's:>:&\n:g' filename

Regards,
Mayur
# 6  
Old 08-19-2011
This User Gave Thanks to yazu For This Post:
# 7  
Old 08-19-2011
@Yazu

nice link
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split xml file into multiple xml based on letterID

Hi All, We need to split a large xml into multiple valid xml with same header(2lines) and footer(last line) for N number of letterId. In the example below we have first 2 lines as header and last line as footer.(They need to be in each split xml file) Header: <?xml version="1.0"... (5 Replies)
Discussion started by: vx04
5 Replies

2. Shell Programming and Scripting

Split XML file based on tags

Hello All , Please help me with below requirement I want to split a xml file based on tag.here is the file format <data-set> some-information </data-set> <data-set1> some-information </data-set1> <data-set2> some-information </data-set2> I want to split the above file into 3... (5 Replies)
Discussion started by: Pratik4891
5 Replies

3. Shell Programming and Scripting

Perl : to split the tags from xml file

I do have an xml sheet as below where I need the perl script to filter only the hyperlink tags. <cols><col min="1" max="1" width="30.5703125" customWidth="1"/><col min="2" max="2" width="7.140625" bestFit="1" customWidth="1"/> <col min="3" max="3" width="32.28515625" bestFit="1"... (3 Replies)
Discussion started by: scriptscript
3 Replies

4. Shell Programming and Scripting

Split XML file

Hi Experts, Can you please help me to split following XML file based on new Order ? Actual file is very big. I have taken few lines of it. <?xml version="1.0" encoding="utf-8" standalone="yes"?> <Orders xmlns='http://www.URL.com/Orders'> <Order> <ORDNo>450321</ORDNo> ... (3 Replies)
Discussion started by: meetmedude
3 Replies

5. Shell Programming and Scripting

Split xml file into many

Hi, I had a scenario need a help as I am new to this. I have a xml file employee.xml with the below content. <Organisation><employee>xxx</employee><employee>yyy</employee><employee>zzz</employee></Organisation> I want to split the file into multiple file as below. Is there a specifice way... (5 Replies)
Discussion started by: mankuar
5 Replies

6. Shell Programming and Scripting

Split a 30GB XML file into 16 pieces

I have a 30 GB XMl file which looks like this: <page> <title>APRIL</title> .........(text contents that I need to extract and store in 1.dat including the <title> tag) </page> <page> <title>August</title> ....(text contents that I need to store in 2.dat including the <title> tag) </page>... (13 Replies)
Discussion started by: shoaibjameel123
13 Replies

7. Shell Programming and Scripting

Getting Proper Date Format in SH Script

There's a small SH script I'm trying to write where it will get the current month and find a log file that is based on the date. Example: Today is February, so the log file is going to be 201102.log (2011 + 02) An additional thing is that if today is the 1st of a month, it will also find the log... (3 Replies)
Discussion started by: kooshi
3 Replies

8. Shell Programming and Scripting

Output file not displayed in the proper format

Hi am using uuencode fro attaching one report which is nothing but sql query output. But when i receive the report through attachement and when it is opened the report is not displayed in proper format. Means if the sql query has 100 rows the mail attachment report displays the report in 2... (2 Replies)
Discussion started by: weknowd
2 Replies

9. Shell Programming and Scripting

Check for proper e mail id format

Hi, We run an application called meta which reads user information from database and updates in LDAP.For that we have some scripts to check the uniqueness of mail ids between the existing LDAP and Database.It works fine when people enter mail ids in proper format (xxx.yyy@abc.com) but if it... (2 Replies)
Discussion started by: prolay
2 Replies

10. Shell Programming and Scripting

Shell script to split XML file

Hi, I'm experiencing difficulty in loading an XML file to an Oracle destination table.I keep running into a memory problem due to the large size of the file. I want to split the XML file into several smaller files based on the keyword(s)/tags : '' and '' and would like to use a Unix shell... (2 Replies)
Discussion started by: bayflash27
2 Replies
Login or Register to Ask a Question