How to split the xml code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to split the xml code
# 1  
Old 01-18-2012
How to split the xml code

Code:
[<?xml version="1.0" encoding="UTF-8"?><FeedAcknowledgement>
<FeedHeader>
<FeedRunId>ID:2d34666235326237663a31333266393636366465633a2d37</FeedRunId>
<FeedName>CLASSIFICATIONMASTER</FeedName>
<AsOf>10/13/2011</AsOf>
<FeedReceivedMode>MQ</FeedReceivedMode>
</FeedHeader>
<Details>
<State>PROCESSED</State>
<Status>FAILED</Status>
<ErrorMessage>Feed definition not found for a give feed name:CLASSIFICATIONMASTER. Please verify the feed name!!</ErrorMessage>
<TimeStamp TimeZone="EST">2011-10-13 18:43:56.524</TimeStamp>
<AsAt TimeZone="EST">2011-10-13 18:43:51.047</AsAt>
</Details>
</FeedAcknowledgement>
]
[<?xml version="1.0" encoding="UTF-8"?><FeedAcknowledgement>
<FeedHeader>
<FeedRunId>403f5086:132f95adad8:-7fe3</FeedRunId>
<FeedName>SECURITYPARTIES</FeedName>
<AsOf>10/12/2011</AsOf>
<FeedReceivedMode>MQ</FeedReceivedMode>
</FeedHeader>
<Details>
<State>PROCESSED</State>
<Status>SUCCESS</Status>
<TimeStamp TimeZone="EST">2011-10-13 18:45:47.923</TimeStamp>
<AsAt TimeZone="EST">2011-10-13 18:45:41.386</AsAt>
<MetaData>
<HierarchyLevels>
<HierarchyLevel>
<Level>1</Level>
<LevelIdentifier>NONE</LevelIdentifier>
<TotalNumRowsInFeed>40</TotalNumRowsInFeed>
<NumRowsSuccessful>40</NumRowsSuccessful>
<NumRowsInError>0</NumRowsInError>
<MappedCategory>DEAM_SECURITY_PARTIES</MappedCategory>
</HierarchyLevel>
</HierarchyLevels>
</MetaData>
</Details>
</FeedAcknowledgement>
]

I have the file which contain the xml code.. I want to split all the xml code. Each xml code starts with "[" and ends with "]".
HOw can I split the each xml code in to seprate file

Last edited by radoulov; 01-18-2012 at 08:14 AM.. Reason: Code tags.
# 2  
Old 01-18-2012
Code:
perl -ne '
if (/\[<\?xml/../^\]/) {
    (/\[<\?xml/) && ($f=sprintf "%02d", $i);
    open O,">> file$f"; print O; close O;
    (/^\]/) && $i++
}' inputfile

For the sample input given, you'll get two files viz. file00 and file01 each containing an xml.
# 3  
Old 01-18-2012
Thank you.. Here I want to compare the string in each XML code . If the strin present then move the specific XML code in to a file.. I dont want to create all the files . It is possible using awk ?. beacuse am not familiar with perl
# 4  
Old 01-18-2012
@arukuku
1. Please be clear as to what exactly you're looking for.
2. You initial post did not mention anything about "compare the string".
3. It is of course possible in awk.
4. What is it that has to be compared?
5. What are the conditions that dictate the comparison?
# 5  
Old 01-19-2012
Code:
[<?xml version="1.0" encoding="UTF-8"?><ESP_SSIA_ACC_FEED>
<BATCH_ID>01112012034346646BTLJ3448</BATCH_ID>
<UID>1326271480221</UID>
<FEED_TYPE>FULL</FEED_TYPE>
<MART_NAME>SSIA_DM_TRANSACTIONS</MART_NAME>
<MART_TYPE>SSIA_TRANSACTIONS</MART_TYPE>
<CLIENT_ID>ESPDB</CLIENT_ID>
<SQL>FROM  SSIA_DM_TRANSACTIONS  WHERE   ASAT BETWEEN '2012-01-10T03:44:48.385' and '2012-01-11T03:43:46.646' AND       SSIA_ACCOUNT_CODE = 'BTLJ3448' AND PORTFOLIO_CODE = 'J03448' </SQL>
</ESP_SSIA_ACC_FEED>
]
[<?xml version="1.0" encoding="UTF-8"?><ESP_SSIA_ACC_FEED>
<BATCH_ID>01112012034346646BTAL2464</BATCH_ID>
<UID>1326271480355</UID>
<FEED_TYPE>FULL</FEED_TYPE>
<MART_NAME>SSIA_DM_TRANSACTIONS</MART_NAME>
<MART_TYPE>SSIA_TRANSACTIONS</MART_TYPE>
<CLIENT_ID>ESPDB</CLIENT_ID>
<SQL>FROM  SSIA_DM_TRANSACTIONS  WHERE   ASAT BETWEEN '2012-01-10T03:44:48.385' and '2012-01-11T03:43:46.646' AND       SSIA_ACCOUNT_CODE = 'BTAL2464' AND PORTFOLIO_CODE = 'B02464' </SQL>
</ESP_SSIA_ACC_FEED>
]
[<?xml version="1.0" encoding="UTF-8"?><ESP_SSIA_ACC_FEED>
<BATCH_ID>01112012034346646BTAC466G</BATCH_ID>
<UID>1326271480521</UID>
<FEED_TYPE>FULL</FEED_TYPE>
<MART_NAME>SSIA_DM_TRANSACTIONS</MART_NAME>
<MART_TYPE>SSIA_TRANSACTIONS</MART_TYPE>
<CLIENT_ID>ESPDB</CLIENT_ID>
<SQL>FROM  SSIA_DM_TRANSACTIONS  WHERE   ASAT BETWEEN '2012-01-10T03:44:48.385' and '2012-01-11T03:43:46.646' AND       SSIA_ACCOUNT_CODE = 'BTAC466G' AND PORTFOLIO_CODE = '17466G' </SQL>
</ESP_SSIA_ACC_FEED>
]
[<?xml version="1.0" encoding="UTF-8"?><ESP_SSIA_ACC_FEED>^M
  <BATCH_ID>10142011103500856BTAL2464</BATCH_ID>^M
  <UID>1318603038699</UID>^M
  <FEED_TYPE>FULL</FEED_TYPE>^M
  <MART_NAME>SSIA_DM_TRANSACTIONS</MART_NAME>^M
  <MART_TYPE>SSIA_TRANSACTIONS</MART_TYPE>^M
  <CLIENT_ID>ESPDB</CLIENT_ID>^M
  <SQL>FROM SSIA_DM_TRANSACTIONS WHERE ASAT BETWEEN^M
  '2012-01-10T00:00:00.001' and '2012-01-10T23:59:59.999' AND^M
  SSIA_ACCOUNT_CODE = 'BTAL2464' AND PORTFOLIO_CODE = 'BTAL2464'</SQL>^M
[<?xml version="1.0" encoding="UTF-8"?><ESP_SSIA_ACC_FEED>^M
<BATCH_ID>01112012034346646BTAL2464</BATCH_ID>^M
<UID>1326271480355</UID>^M
<FEED_TYPE>FULL</FEED_TYPE>^M
<MART_NAME>SSIA_DM_TRANSACTIONS</MART_NAME>^M
<MART_TYPE>SSIA_TRANSACTIONS</MART_TYPE>^M
<CLIENT_ID>ESPDB</CLIENT_ID>^M
<SQL>FROM  SSIA_DM_TRANSACTIONS  WHERE   ASAT BETWEEN '2012-01-10T03:44:48.385' and '2012-01-11T03:43:46.646' AND       SSIA_ACCOUNT_CODE = 'BTAL2464' AND PORTFOLIO_CODE = 'B02464' </SQL>^M
</ESP_SSIA_ACC_FEED>^M
]
[<?xml version="1.0" encoding="UTF-8"?><ESP_SSIA_ACC_FEED>  <BATCH_ID>0118201201130853940</BATCH_ID>  <UID>1326867190825</UID>  <FEED_TYPE>FULL</FEED_TYPE>  <MART_NAME>SSIA_DM_SECMASTER</MART_NAME>  <MART_TYPE>SSIA_SECMASTER</MART_TYPE>  <CLIENT_ID>ESPDB</CLIENT_ID>  <SQL>FROM        SSIA_DM_SECMASTER    WHERE        ASOF BETWEEN '2012-01-17'  AND '2012-01-18' AND        ASAT BETWEEN '2012-01-17T03:56:01.170' AND '2012-01-18T01:13:08.539' AND        ASSET_TYPE_CODE = 40      </SQL>
</ESP_SSIA_ACC_FEED>
]
[<?xml version="1.0" encoding="UTF-8"?><ESP_SSIA_ACC_FEED>  <BATCH_ID>0118201201130853910</BATCH_ID>  <UID>1326867191296</UID>  <FEED_TYPE>FULL</FEED_TYPE>  <MART_NAME>SSIA_DM_SECMASTER</MART_NAME>  <MART_TYPE>SSIA_SECMASTER</MART_TYPE>  <CLIENT_ID>ESPDB</CLIENT_ID>  <SQL>FROM        SSIA_DM_SECMASTER    WHERE        ASOF BETWEEN '2012-01-17'  AND '2012-01-18' AND        ASAT BETWEEN '2012-01-17T03:56:01.170' AND '2012-01-18T01:13:08.539' AND        ASSET_TYPE_CODE = 10      </SQL>
</ESP_SSIA_ACC_FEED>
]

Sorry.... The file contains bunch of XML code. Search for the id (Eg:01112012034346646BTAL2464) and pull the xml associated with the id.

Last edited by Franklin52; 01-19-2012 at 03:53 AM.. Reason: Please use code tags for code and data samples, thank you
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

XML - Split And Extract String between Chars

Hi, I am trying to read the records from file and split into multiple files. SourceFile.txt <?xml version="1.0" encoding="UTF-8"?>... (2 Replies)
Discussion started by: unme
2 Replies

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

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

8. Shell Programming and Scripting

Need to split a xml file in proper format

Hi, I have a file which has xml data but all in single line Ex - <?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- <?xml version="1.0"?> <User> <Name>Robert</Name>... (6 Replies)
Discussion started by: avishek007
6 Replies

9. Shell Programming and Scripting

Need to Split Big XML into multiple xmls

Hi friends.. We have urgent requirement.We need to split the big xml having multiple orders into multiple xmls having each order in each xml. For Example In input XMl will be in following format with multiple line orders.. <OrderDetail BillToKey="20100805337" Createuserid="CreateGuestOrder"... (8 Replies)
Discussion started by: dprakash
8 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