aspose file tools*
The moose likes XML and Related Technologies and the fly likes Converting XML into legacy record layout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Converting XML into legacy record layout" Watch "Converting XML into legacy record layout" New topic
Author

Converting XML into legacy record layout

Suresh Kanagalingam
Ranch Hand

Joined: Aug 17, 2001
Posts: 82
Hello all,
I need to convert some XML files into legacy format record layout. For example legacy record layout may look like this(delimeterd by '|'):
100|First Name|Last Name|Address
200|20021231|12:59 PM|Purchase|Credit Card
300|3735******|1023
Can any one suggest how I can do this? One option I am thinking is writing a Java program to parse the file and write out each element as it encounters, but this does not sound like the best solution.
Thanks
Suresh
Ritu Kama
Ranch Hand

Joined: Sep 10, 2001
Posts: 72
Hi,
You can set the output method to text in your XSL - for e.g.
<xsl utput method="text"/>
Then use <xsl:for-each> to iterate over each XML node that represents the record and output the content.
Please provide with your sample XML so that we can help you better.
Thanks
Ritu
Suresh Kanagalingam
Ranch Hand

Joined: Aug 17, 2001
Posts: 82
Thanks for the reply Ritu. When you say 'set the output method..' where do I set the output method? Can you explain in detail. Also I have attached a sample XML here.
Thanks in advace.
Suresh

(code tag supplied)
[ November 13, 2002: Message edited by: Mapraputa Is ]
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Pretty hard to read the XML that way, with no indentation and no DTD. Could you use the UBB "CODE" tags to indent it?


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
You set the output method exactly as Rita showed:
<xslutput method="text"/>
Put this somewhere at the top level of your XSL stylesheet (that is, as a child of the
<xsl:stylesheet> element).
[ November 13, 2002: Message edited by: Ron Newman ]
Suresh Kanagalingam
Ranch Hand

Joined: Aug 17, 2001
Posts: 82
Here is the XML with UBB code
<?xml version = "1.0" encoding = "UTF-8"?>
<MessageSet xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation = "message.xsd" Version = "1.0">
<Message>
<MessageCreate>
<Date>20010701</Date>
<Time>121212</Time>
<Source Participant = "D">
<DlrCode>9000</DlrCode>
</Source>
<Target Participant = "F">
<MgmtCode>DDD</MgmtCode>
</Target>
</MessageCreate>
<Network NtwrkID = "TEST">
<Date>20010701</Date>
<Time>121213</Time>
</Network>
<MessageType>
<Request SourceID = "200107011212121" MessageID = "0000001">
<ClerkID>JOE</ClerkID>
<Account>
<AcctLookup>
<DlrLookup>
<AcctDesignation>2</AcctDesignation>
<AcctType>01</AcctType>
<DlrCode>9000</DlrCode>
<DlrAcctID>12345678910</DlrAcctID>
</DlrLookup>
</AcctLookup>
</Account>
<BusProcess>
<AddModAddress>
<Address AddressCode="2">
<AddressLine>12 MY AVE</AddressLine>
<City>MY CITY</City>
<ProvState>ON</ProvState>
<Country>CAN</Country>
<PostalZip>M3J5R5</PostalZip>
</Address>
<TaxCode>ON</TaxCode>
</AddModAddress>
</BusProcess>
</Request>
</MessageType>
</Message>
<Message>
<MessageCreate>
<Date>20010701</Date>
<Time>121212</Time>
<Source Participant = "D">
<DlrCode>9000</DlrCode>
</Source>
<Target Participant = "F">
<MgmtCode>DDD</MgmtCode>
</Target>
</MessageCreate>
<Network NtwrkID = "TEST">
<Date>20010701</Date>
<Time>121213</Time>
</Network>
<MessageType>
<Request SourceID = "200107011212122" MessageID = "0000002">
<ClerkID>JOE</ClerkID>
<Account>
<AcctLookup>
<DlrLookup>
<AcctDesignation>2</AcctDesignation>
<AcctType>01</AcctType>
<DlrCode>9000</DlrCode>
<DlrAcctID>12458963342</DlrAcctID>
</DlrLookup>
</AcctLookup>
</Account>
<BusProcess>
<AddModAddress>
<Address AddressCode="2">
<AddressLine>12 HER STREET</AddressLine>
<City>HER CITY</City>
<ProvState>ON</ProvState>
<Country>CAN</Country>
<PostalZip>L5M8U7</PostalZip>
</Address>
<TaxCode>ON</TaxCode>
</AddModAddress>
</BusProcess>
</Request>
</MessageType>
</Message>
<Message>
<MessageCreate>
<Date>20010701</Date>
<Time>121212</Time>
<Source Participant = "D">
<DlrCode>9000</DlrCode>
</Source>
<Target Participant = "F">
<MgmtCode>DDD</MgmtCode>
</Target>
</MessageCreate>
<Network NtwrkID = "TEST">
<Date>20010701</Date>
<Time>121213</Time>
</Network>
<MessageType>
<Request SourceID = "200107011212123" MessageID = "0000003">
<ClerkID>JOE</ClerkID>
<Account>
<AcctLookup>
<DlrLookup>
<AcctDesignation>2</AcctDesignation>
<AcctType>01</AcctType>
<DlrCode>9000</DlrCode>
<DlrAcctID>12458963356</DlrAcctID>
</DlrLookup>
</AcctLookup>
</Account>
<BusProcess>
<AddModAddress>
<Address AddressCode="2">
<AddressLine>1662 ALL CR.</AddressLine>
<City>ALL CITY</City>
<ProvState>ON</ProvState>
<Country>CAN</Country>
<PostalZip>Z6Y4R5</PostalZip>
</Address>
<TaxCode>ON</TaxCode>
</AddModAddress>
</BusProcess>
</Request>
</MessageType>
</Message>
</MessageSet>
Suresh Kanagalingam
Ranch Hand

Joined: Aug 17, 2001
Posts: 82
Sorry folks...
For some reason even though I enabled UBB code it is still not doing the indentation!
Thanks
Suresh
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Suresh, you need to put [code] before your code, and [/code] after. So it will be
[code]
<?xml version = "1.0" encoding = "UTF-8"?>
...
[/code]
[ November 13, 2002: Message edited by: Mapraputa Is ]

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Suresh Kanagalingam
Ranch Hand

Joined: Aug 17, 2001
Posts: 82
Ok.. here it is:

[ November 15, 2002: Message edited by: Mapraputa Is ]
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Much better. Now, is there a DTD that describes this XML? (XSLT doesn't need one, but it will help document the input file format.)
And can you define the legacy file format precisely, describing (in English for now) what fields you what to transfer from the XML to the legacy file?
In your first message, I don't know where many of the fields are coming from. Perhaps you could show us a real legacy record that derives from a real record in the input XML.
Suresh Kanagalingam
Ranch Hand

Joined: Aug 17, 2001
Posts: 82
Hi Ron,
There is a DTD, but I did not receive it for testing.
Here is the explanation for what I need to do.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Here's a first pass at what you want. It may not be exactly right, but you can start from here and tweak it.
Feel free to ask any questions about what it does and how it works.
Ritu Kama
Ranch Hand

Joined: Sep 10, 2001
Posts: 72
Hi,
Did you finally figure it out? I couldn't check the forum after initial post
Ritu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting XML into legacy record layout