473,394 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

getting the value from text file to xml

I am working in ASP.NET with C#. I have a text file which contains datas
with delimiters. For example:-

MSH|^~\$|DISCHARGE|CLAY COUNTY MEMORIAL|||200502110939|

I also have an XML file created with predefined tags. Some of the tags
contain child element. I need to pass the data from the text file i.e the
value within the delimiters should be passed to the corresponding tags within
the XML file. I have done this through hard code. But i need it to be
dynamic. There are also possibilities to add or delete tags from the XML file
which should not affect the code. I have created the XML using Dataset. So
the addition or deletion of tags can be done through dataset without
affecting the code.

This the XMl file
<?xml version="1.0" standalone="yes"?>
<Dataset1 xmlns="http://tempuri.org/Dataset1.xsd">
<MSH>
<FieldSeparator>|</FieldSeparator>
<EncodingCharacters>^~\$</EncodingCharacters>
<DateTimeOfMessage>200502110938</DateTimeOfMessage>
<Security />
<MessageControlID>00860</MessageControlID>
<SequenceNumber />
<ContinuationPointer />
<AcceptAcknowledgmentType />
<ApplicationAcknowledgmentType />
<CountryCode />
<CharacterSet />
<AlternateCharacterSetHandlingScheme />
<SendingApplication>
<namespaceid>ADMIT</namespaceid>
<universalid>abc</universalid>
<universalidtype>xyz</universalidtype>
</SendingApplication>
<SendingFacility>
<namespaceid>CLAY COUNTY MEMORIAL</namespaceid>
<universalid />
<universalidtype />
</SendingFacility>
<ReceivingApplication>
<namespaceid />
<universalid />
<universalidtype />
</ReceivingApplication>
<ReceivingFacility>
<namespaceid />
<universalid />
<universalidtype />
</ReceivingFacility>
<MessageType>
<messagetype>ADT</messagetype>
<triggerevent>A01</triggerevent>
<messagestructure />
</MessageType>
<ProcessingID>
<processingID>P</processingID>
<processingMode />
</ProcessingID>
<Version>
<versionID>2.2</versionID>
<internationalizationcode />
<internalversionID />
</Version>
<PrincipalLanguageOfMessage>
<identifier />
<text />
<nameofcodingsystem />
<alternateidentifier />
<alternatetext />
<nameofalternatecodingsystem />
</PrincipalLanguageOfMessage>
</MSH>
</Dataset1>

This is the hard code i have used:
/* MSH class file */
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Schema;
using System.IO;

namespace HL7_XML
{
/// <summary>
/// Summary description for MSH.
/// </summary>
public class MSH
{
public MSH()
{}

/* Global Declarations */
string line,SA,SF,RA;
string currentLine;
string datafield = "|" + "|" + "|" + "|" + "|" + "|" + "|" + "|" + "|" +
"|" + "|" + "|" + "|" + "|" + "|" + "|" + "|";
string component = "^" + "^" + "^" + "^" + "^" + "^" + "^" + "^" + "^";
StreamReader myReader;
string[] sub_splitout=new string[20];
char[] sub_splitter={'^'};
char[] splitter = {'|'};
string[] splitout = new string[20];

public void msgheader()
{
/* Reading the HL-7 file i.e. to be converted into XML file */
try
{
myReader = File.OpenText("C:/HL7/HL7-XML/upload/input.txt");
}
catch (IOException e1)
{
Console.WriteLine(e1.ToString());
Console.WriteLine(e1.Message);
return;
}
do
{
try
{
/* Reading the HL-7 file line by line */
currentLine = myReader.ReadLine();
line = currentLine + datafield;
if (line.StartsWith("MSH"))
{
splitout = line.Split(splitter);

for (int i = 0; i <= splitout.Length; i++)
{
/* Creating Dataset for MSH */
Dataset1 ds=new Dataset1();
Dataset1.MSHRow MSH_row = ds.MSH.NewMSHRow();

/* Assigning the values of HL-7 file to MSH Table of Dataset1. */
MSH_row.FieldSeparator="|";
MSH_row.EncodingCharacters=splitout[1];
MSH_row.DateTimeOfMessage=splitout[6];
MSH_row.Security=splitout[7];
MSH_row.MessageControlID=splitout[9];
MSH_row.SequenceNumber=splitout[12];
MSH_row.ContinuationPointer=splitout[13];
MSH_row.AcceptAcknowledgmentType=splitout[14];
MSH_row.ApplicationAcknowledgmentType=splitout[15];
MSH_row.CountryCode=splitout[16];
MSH_row.CharacterSet=splitout[17];
MSH_row.AlternateCharacterSetHandlingScheme=splito ut[19];

ds.MSH.AddMSHRow(MSH_row);
ds.AcceptChanges();

/* Assigning the values of HL-7 file to Sending Application Table of
Dataset1 */
SA= splitout[2];
string new_string=SA+component;
sub_splitout=new_string.Split(sub_splitter);

for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.SendingApplicationRow sf_row =
ds.SendingApplication.NewSendingApplicationRow();
sf_row.namespaceid=sub_splitout[0];
sf_row.universalid=sub_splitout[1];
sf_row.universalidtype=sub_splitout[2];
sf_row.MSHRow=MSH_row;
ds.SendingApplication.AddSendingApplicationRow(sf_ row);
ds.AcceptChanges();
}

/* Assigning the values of HL-7 file to Sending Facility Table of
Dataset1 */
SF= splitout[3];
string new_string1=SF+component;
sub_splitout=new_string1.Split(sub_splitter);

for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.SendingFacilityRow sf_row =
ds.SendingFacility.NewSendingFacilityRow();
sf_row.namespaceid=sub_splitout[0];
sf_row.universalid=sub_splitout[1];
sf_row.universalidtype=sub_splitout[2];
sf_row.MSHRow=MSH_row;
ds.SendingFacility.AddSendingFacilityRow(sf_row);
ds.AcceptChanges();
}

/* Assigning the values of HL-7 file to Receiving Application Table
of Dataset1*/
RA= splitout[4];
string new_string2=RA+component;
sub_splitout=new_string2.Split(sub_splitter);

for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.ReceivingApplicationRow sf_row =
ds.ReceivingApplication.NewReceivingApplicationRow ();
sf_row.namespaceid=sub_splitout[0];
sf_row.universalid=sub_splitout[1];
sf_row.universalidtype=sub_splitout[2];
sf_row.MSHRow=MSH_row;
ds.ReceivingApplication.AddReceivingApplicationRow (sf_row);
ds.AcceptChanges();
}

/* Assigning the values of HL-7 file to Receiving Facility Table of
Dataset1 */
string RF= splitout[5];
string new_string3=RF+component;
sub_splitout=new_string3.Split(sub_splitter);

for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.ReceivingFacilityRow sf_row =
ds.ReceivingFacility.NewReceivingFacilityRow();
sf_row.namespaceid=sub_splitout[0];
sf_row.universalid=sub_splitout[1];
sf_row.universalidtype=sub_splitout[2];
sf_row.MSHRow=MSH_row;
ds.ReceivingFacility.AddReceivingFacilityRow(sf_ro w);
ds.AcceptChanges();
}

/* Assigning the values of HL-7 file to Message Type Table of
Dataset1 */
string MT= splitout[8];
string new_string4=MT+component;
sub_splitout=new_string4.Split(sub_splitter);

for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.MessageTypeRow sf_row = ds.MessageType.NewMessageTypeRow();
sf_row.messagetype=sub_splitout[0];
sf_row.triggerevent=sub_splitout[1];
sf_row.messagestructure=sub_splitout[2];
sf_row.MSHRow=MSH_row;
ds.MessageType.AddMessageTypeRow(sf_row);
ds.AcceptChanges();
}

/* Assigning the values of HL-7 file to ProcessingID Table of
Dataset1 */
string PID= splitout[10];
string new_string5=PID+component;
sub_splitout=new_string5.Split(sub_splitter);

for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.ProcessingIDRow sf_row =
ds.ProcessingID.NewProcessingIDRow();
sf_row.processingID=sub_splitout[0];
sf_row.processingMode=sub_splitout[1];
sf_row.MSHRow=MSH_row;
ds.ProcessingID.AddProcessingIDRow(sf_row);
ds.AcceptChanges();
}

/* Assigning the values of HL-7 file to version Table of Dataset1 */
string version= splitout[11];
string new_string6=version+component;
sub_splitout=new_string6.Split(sub_splitter);

for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.VersionRow sf_row = ds.Version.NewVersionRow();
sf_row.versionID=sub_splitout[0];
sf_row.internationalizationcode=sub_splitout[1];
sf_row.internalversionID=sub_splitout[2];
sf_row.MSHRow=MSH_row;
ds.Version.AddVersionRow(sf_row);
ds.AcceptChanges();
}
/* Assigning the values of HL-7 file to Principal Language Of Message
Table of Dataset1 */
string PLM= splitout[18];
string new_string7=PLM+component;
sub_splitout=new_string7.Split(sub_splitter);

for(int j=sub_splitout.Length;j<=sub_splitout.Length;j++)
{
Dataset1.PrincipalLanguageOfMessageRow sf_row =
ds.PrincipalLanguageOfMessage.NewPrincipalLanguage OfMessageRow();
sf_row.identifier=sub_splitout[0];
sf_row.text=sub_splitout[1];
sf_row.nameofcodingsystem=sub_splitout[2];
sf_row.alternateidentifier=sub_splitout[3];
sf_row.alternatetext=sub_splitout[4];
sf_row.nameofalternatecodingsystem=sub_splitout[5];
sf_row.MSHRow=MSH_row;
ds.PrincipalLanguageOfMessage.AddPrincipalLanguage OfMessageRow(sf_row);
ds.AcceptChanges();
}
ds.WriteXml("C:/HL7/HL7-XML/msh.xml");
}
}

}
catch (EndOfStreamException e2)
{
Console.WriteLine(e2.Message);
}
finally
{
}
} while (currentLine != null);
myReader.Close();
myReader = null;

}
}
}
Plz provide me with a solution. Iam desperate. Thanx in advance.
Aug 25 '06 #1
1 1847
"Jerry John" <Jerry Jo**@discussions.microsoft.comwrote in message
news:E4**********************************@microsof t.com...
I am working in ASP.NET with C#. I have a text file which contains datas
with delimiters. For example:-

MSH|^~\$|DISCHARGE|CLAY COUNTY MEMORIAL|||200502110939|

I also have an XML file created with predefined tags. Some of the tags
contain child element. I need to pass the data from the text file i.e the
value within the delimiters should be passed to the corresponding tags
within
the XML file. I have done this through hard code. But i need it to be
dynamic. There are also possibilities to add or delete tags from the XML
file
which should not affect the code. I have created the XML using Dataset. So
the addition or deletion of tags can be done through dataset without
affecting the code.
Jerry, sorry not to provide a solution, but did you know there are companies
who do this sort of conversion for a living? There are both products and
services whicch can do this for you - correctly.

A google search for "hl7 xml transform" found 46,000 entries. The first
among them was "CONVERT EDI TO XML" at
http://www.stylusstudio.com/convert_edi_to_xml.html. I found it useful for
understanding the nature of the problem, even though I'm not personally
interested in the solution (not yet - we have people for that!)
John
Aug 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dan glenn | last post by:
hi. I want to code a 'preview' function into a guestbook entry page. I can do it with a button that posts, bringing up a whole new page showing a preview of what has been entered, and then the user...
5
by: Ram [MSFT] | last post by:
Hi All, I'm trying to programatically (using c#) read the file properties (Title, Summary, Author, Comments etc.... The stuff that shows up on the Summary tab when you see the properties of a...
0
by: renateves | last post by:
My problem is that i have a xml file that is convert into a table (by xsl) in a aspx file, and in vb code i want to get and put some values to the table. Is the code: ASPX FILE <Get the...
5
by: Larry | last post by:
I get a "Specified cast is not valid" when excuting the following line in the subroutine below: spParm = spAddImage.Parameters("@fnameIn").Value = ckfile.Text I'm not sure what I'm doing...
10
by: eggie5 | last post by:
Is it possible to get a file without using a form post? I want to get the data (bytes) of a file, text or binary, and just save it to a variable. Similar to the post body of a form that has a...
4
by: bushi | last post by:
hi ! i have following code to display some text on a web form,after getting it from database. <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"> <ItemTemplate>...
6
by: sathyashrayan | last post by:
Dear Group, Please look at the following demo link. http://www.itsravi.com/demo/new_pms/admin/addproject.php
9
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of...
9
vikas251074
by: vikas251074 | last post by:
I am not getting date value in spite of my good effort. This code was working in my last office where I work. Now I am trying to work at my home pc. but not getting date value. Any can help me why...
7
vikas251074
by: vikas251074 | last post by:
I am getting error above in following code since few days giving tension day and night. How can I solve this? I am facing since Oct.25. in line no. 362 After doing a lot of homework, I am...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.