i have a text file that has delimiters.
(i.e. MSH|^~\$|ADMIT|CLAY COUNTY MEMORIAL|||200502110938||ADT^A01|00860|P|2.2|||||| )
Using C# i need to
Read this file, segment by segment and write these segments into the appropriate XML tags of a XML file
I have considered the datas within the delimiters as segments.
i.e. my segments would be as below
MSH
^~\$
ADMIT
CLAY COUNTY MEMORIAL
200502110938
ADT^A01
00860
P
2.2
The empty space within the delimiters are considered as null data
Now i want to write these segments into XMl file within its appropriate tags.

how to write into XML
pmanisekaran
(i.e. MSH|^~\$|ADMIT|CLAY COUNTY MEMORIAL|||200502110938||ADT^A01|00860|P|2.2|||||| )
Using C# i need to
Read this file, data by data and write these datas into the appropriate XML tags of a XML file
i.e. my datas for a segment"MSH" (i.e root element) would be as below
MSH--->root element
^~\$
ADMIT
CLAY COUNTY MEMORIAL
200502110938
ADT^A01
00860
P
2.2
I may have 20attributes in my destination xml file.But the data in my segment may be <=20.Then how can i insert the datas into the corresponding tags of an already created xmlfile
The empty space within the delimiters are considered as null data
Now i want to write these datas into already created XMl file within its appropriate tags.
progames25
Hi,
You can do the following:
1) First split the text as follow:
string YourLine; string[] SplitLine;SplitLine = YourLine.Split(
"|");2) Create an XML document an iterate:
XmlDocument
XMLDocument= new XmlDocument("YourTableName"); XmlElement MainElement = XMLDocument.CreateElement("EntryName");XMLDocument.SetAttribute("FirstAttributte", SplitLine[0]);
XMLDocument.SetAttribute("SecondAttributte", SplitLine[1]);
XMLDocument.AppendChild(MainElement);
Hope this helps
Regards
qwv
Hi
This sample code will help with xml tags, you can use something like this to read the text file, at the end I put a foreach to diplay the data in the arraylist :-
private void Read_Data(object sender, EventArgs e)
{
ArrayList list_data = new ArrayList();
try {
this.Hide();
StreamReader Data_In = new StreamReader(new FileStream(@"C:/path.txt", FileMode.Open, FileAccess.Read));
while (Data_In.Peek() != -1)
{
string row = Data_In.ReadLine();
string[] columns = row.Split('|');
if (columns[0] != "")
{
list_data.Add(columns[0]);
}
if (columns[1] != "")
{
list_data.Add(columns[1]);
}
if (columns[2] != "")
{
list_data.Add(columns[2]);
}
if (columns[3] != "")
{
list_data.Add(columns[3]);
}
if (columns[4] != "")
{
list_data.Add(columns[4]);
}
if (columns[5] != "")
{
list_data.Add(columns[5]);
}
if (columns
{
list_data.Add(columns
}
if (columns[7] != "")
{
list_data.Add(columns[7]);
}
if (columns
{
list_data.Add(columns
}
if (columns[9] != "")
{
list_data.Add(columns[9]);
}
if (columns[10] != "")
{
list_data.Add(columns[10]);
}
if (columns[11] != "")
{
list_data.Add(columns[11]);
}
if (columns[12] != "")
{
list_data.Add(columns[12]);
}
if (columns[13] != "")
{
list_data.Add(columns[13]);
}
if (columns[14] != "")
{
list_data.Add(columns[14]);
}
if (columns[15] != "")
{
list_data.Add(columns[15]);
}
if (columns[16] != "")
{
list_data.Add(columns[16]);
}
if (columns[17] != "")
{
list_data.Add(columns[17]);
}
}
Data_In.Close();
foreach (string data in list_data)
{
MessageBox.Show(data);
}
}
catch {
}