TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Alemus Ledreog
NA
2
0
HELP! Need to write an XML file to a Fixed Position Flat File
Aug 24 2005 11:51 AM
I am trying to read data from XML elements and load them into a fixed position flat file.
I am using StringBuilder to append the elements to a string. The elements must be stored in "fixed"
positions in the string so that when it is loaded into the flat file, elements appear in the correct poistion.
Here is a sample file layout
Element Start Position Length
First Name 0 15
Last Name 15 20
Address 35 25
Example:
I read an element <firstname>John</firstname>
I append the name "John" into the string starting at position 0.
When I then read the element <lastname>Doe</lastname>,
I must also append the "whitespace" so that the string "Doe" is in position 15 of the string.
Below is a sample of the code I am using:
nodeLst = doc.GetElementsByTagName("firstname");
b.Append(nodeLst.Item(0).InnerText); //inner text would be John
while (c < 15)
{
b.Append(" "); //adds the whitespace so the next element is in the right position
c++;
In the code,
b
is the name of my string,
nodeLst
is an XmlNodeList and
c
is an integer used
as a counter.
This works but it is obviously tedious as this process must be repeated for every element that
must be appended to the string.
Is there a simpler solution I am overlooking? I am somewhat of a neophyte C# programmer.
Any help would be appreciated.
Reply
Answers (
1
)
Help For creating reusable components
Help of memory leak