How to create a fixed length file with an XML document as your source

Hello Experts,
I need to create a fixed length file from my xml data source.  I do not have any idea where to start or what programming language is the best.  I was thinking C#.NET but the file is large with a lot of fields and I did not want to have to type it all out.  Needing a quick solution today if possible.

Thanks!
MiracleByDesignAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MiracleByDesignAuthor Commented:
0
grayeCommented:
To convert a text-based XML file into a binary fixed-length data file would take a bit of work.

Normally, you'd use an XML Style Sheet Transform (XSLT) to convert from XML to another format.  However, most of the "other format" are text-based (such as HTML).  Yes, there is a branch of XSLT that deals with binary ouput called Formatting Objects (XSL-FO), but again... they are designed to output to some known "mostly"-text based format (like PDF).

So, that pretty much means that you're gonna havta write an application to perform this task. If you have some experience with C#, it's not difficult to parse the incomming XML file into a custom class.  Then you'd write code to output the information in the class to a binary file (padding as appropriate to meet the fixed length requirements).
0
MiracleByDesignAuthor Commented:
Hi Graye,

Thank you for your insight.  Could you give me a little coding example to get started?  I have not used XSLT at all,  I just need a little start and then I can take it from there!

Thanks!
Miracle By Design
0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

MiracleByDesignAuthor Commented:
Also the length requirements are in the xml document, anyway we could use this?
0
grayeCommented:
No, I'm suggesting that you NOT use XSLT... and instead write a custom application (perhaps in C#) that will read the XML input and then output binary.

Here is a "classic" example for reading an XML file.
http://support.microsoft.com/kb/307548

Here is a bit more complex example using an custom class that has been configured for serialization:
http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx
0
MiracleByDesignAuthor Commented:
Ok, I have been working on this for about 4 days now and I attempted to look at the links you provided when I googled it.  I guess my question is, since this file has a large number of fields and I have the start position and the length, how to I access this information in order to create my flat file?  I do not want to use the LPad or RPad when I have the data already in the xml document.  This I could not get to work correctly.  Could you provide me with a very small sample of code with just a few fields?  Thanks
0
grayeCommented:
That example at the bottom of the 2nd link is a pretty good place to start.  It shows how to "import" the contents of an XML file into a custom class that you create.  You can choose to keep the Start and Length attributes when you "import" the file.

Then, after you've got all of the data, it'd be somewhat trival to output the contents of the class to a binary file (yes... using LPad-equivalent padding for the text portions).

But, before we get that far, can you show us a sample of what the final output looks like (I've been assuming all along, that this is a binary file format).
0
MiracleByDesignAuthor Commented:
Sure...the attached is a sample of what I am trying to create. EE-Sample-File.txt
0
grayeCommented:
Ok !! so it really is just text output.  My appologies for making the assuming that we were talking about a binary file.   Consequently you can ignore practically everything that I've said up till now.

OK.  yes, this scenariou would lend itself to performing an XSL Transform.   Some questions before we begin...  are the numeric values already padded with zeros and are the string values already padded with spaces (in the XML file)?   If so, this would be somewhat trivial to just ouput the data "as is".  Otherwise, the XSL will have to do the padding for you (but it's not difficult to do).

I'd recommend that you start with doing a little reading at www.w3schools.com to brush up on XSL formatting.  After that, come back here and we'll help you write the XSL file to perform the XML-to-Text translation.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MiracleByDesignAuthor Commented:
Hi Graye,

The numeric values are already padded in the SQL table which populates the XML document.  The space padding is not though so I would need to do that with the XSL formatting.  I am going to the website you providing now and looking up XSL.  Thank you again for your help!
0
MiracleByDesignAuthor Commented:
Hi Graye,

I have looked at the website and I am ready for your examples using XSL if you are still available to help me.  I need to get this file produced tonight if possible.

Thanks,
Miracle By Design
0
grayeCommented:
Wow... no pressure

OK, send me a small chunk of the XML file that has actual (or fake) data
0
MiracleByDesignAuthor Commented:
Sorry for the pressure.  I have been working on this for a week now by myself.  The xml file, scheme and sample data are attached above.  If you do not have time, I understand...no worries!
0
grayeCommented:
But that XML file didn't have any data....
0
MiracleByDesignAuthor Commented:
There are a lot of fields to supply fake data and the real data as EIN and SSN in it.  Can you provide an example of using xsl without the data?
0
MiracleByDesignAuthor Commented:
Most of the name fields in the xml file are pretty easy to figure out the data that goes in there.  For example, name (first, last, middle), delivery address (ex suite 200) location address(1234 s anyplace), EIN-10-99999999, Wages, etc.  This file is to electronically submit W2s so I am behind the gun.  I created one file but it was not in the XML format so the file was rejected.  At this point I am just cutting and pasting the data because I have to get this out today.  I appreciate your help, you if you post a small code sample of how to use XSL to accomplish this task, I will award you the 500 points.  Thanks again!
0
MiracleByDesignAuthor Commented:
Used XML Convert (a free download) that allows you to map your XML document to flat file fields.  http://www.unidex.com/download.htm
0
MiracleByDesignAuthor Commented:
The URL I provided is the coding tool needed to get the job completed.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.