Writing data from dataset to XML file [modified]
-
I can abke to write data from Dataset to XML File but the problem now i am facing is... i am getting the XML file like this - <NewDataSet> - <PatientID> <patientRegId>NH0000412006</patientRegId> <pat_name>SNI dsen dev1</pat_name> <DOB>1980-06-22T00:00:00+05:30</DOB> <gender>Male</gender> <MaritalStatus>Married</MaritalStatus> <Religion>Christian</Religion> <presentAddress /> <city>Chennai</city> <presentPIN>500013</presentPIN> <Nationaity>Indian</Nationaity> <patientRegId1>NH0000412006</patientRegId1> <episodeNo>1</episodeNo> <visitNo>2</visitNo> <consultantId>5</consultantId> </PatientID> </NewDataSet> but i want the same data in this format <NewDataSet> - <PatientID> <patientRegId>NH0000412006</patientRegId> <pat_name>SNI dsen dev1</pat_name> <DOB>1980-06-22T00:00:00+05:30</DOB> <gender>Male</gender> <MaritalStatus>Married</MaritalStatus> <Religion>Christian</Religion> <presentAddress /> <city>Chennai</city> <presentPIN>500013</presentPIN> <Nationaity>Indian</Nationaity> <patientRegId1>NH0000412006</patientRegId1> - <episodeNo No="1"> <visitNo>2</visitNo> <consultantId>5</consultantId> </episodeNo> </PatientID> </NewDataSet> this is my code Dim SqlDataAdapter2 As New SqlDataAdapter(qry, sqlCon) Dim ds As New DataSet SqlDataAdapter2.Fill(ds, "PatientID") ds.WriteXml("E:\\ss.xml") Thanks in Advance
modified on Thursday, January 03, 2008 2:29:20 AM
-
I can abke to write data from Dataset to XML File but the problem now i am facing is... i am getting the XML file like this - <NewDataSet> - <PatientID> <patientRegId>NH0000412006</patientRegId> <pat_name>SNI dsen dev1</pat_name> <DOB>1980-06-22T00:00:00+05:30</DOB> <gender>Male</gender> <MaritalStatus>Married</MaritalStatus> <Religion>Christian</Religion> <presentAddress /> <city>Chennai</city> <presentPIN>500013</presentPIN> <Nationaity>Indian</Nationaity> <patientRegId1>NH0000412006</patientRegId1> <episodeNo>1</episodeNo> <visitNo>2</visitNo> <consultantId>5</consultantId> </PatientID> </NewDataSet> but i want the same data in this format <NewDataSet> - <PatientID> <patientRegId>NH0000412006</patientRegId> <pat_name>SNI dsen dev1</pat_name> <DOB>1980-06-22T00:00:00+05:30</DOB> <gender>Male</gender> <MaritalStatus>Married</MaritalStatus> <Religion>Christian</Religion> <presentAddress /> <city>Chennai</city> <presentPIN>500013</presentPIN> <Nationaity>Indian</Nationaity> <patientRegId1>NH0000412006</patientRegId1> - <episodeNo No="1"> <visitNo>2</visitNo> <consultantId>5</consultantId> </episodeNo> </PatientID> </NewDataSet> this is my code Dim SqlDataAdapter2 As New SqlDataAdapter(qry, sqlCon) Dim ds As New DataSet SqlDataAdapter2.Fill(ds, "PatientID") ds.WriteXml("E:\\ss.xml") Thanks in Advance
modified on Thursday, January 03, 2008 2:29:20 AM
What are the differences?
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
-
What are the differences?
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
-
I can abke to write data from Dataset to XML File but the problem now i am facing is... i am getting the XML file like this - <NewDataSet> - <PatientID> <patientRegId>NH0000412006</patientRegId> <pat_name>SNI dsen dev1</pat_name> <DOB>1980-06-22T00:00:00+05:30</DOB> <gender>Male</gender> <MaritalStatus>Married</MaritalStatus> <Religion>Christian</Religion> <presentAddress /> <city>Chennai</city> <presentPIN>500013</presentPIN> <Nationaity>Indian</Nationaity> <patientRegId1>NH0000412006</patientRegId1> <episodeNo>1</episodeNo> <visitNo>2</visitNo> <consultantId>5</consultantId> </PatientID> </NewDataSet> but i want the same data in this format <NewDataSet> - <PatientID> <patientRegId>NH0000412006</patientRegId> <pat_name>SNI dsen dev1</pat_name> <DOB>1980-06-22T00:00:00+05:30</DOB> <gender>Male</gender> <MaritalStatus>Married</MaritalStatus> <Religion>Christian</Religion> <presentAddress /> <city>Chennai</city> <presentPIN>500013</presentPIN> <Nationaity>Indian</Nationaity> <patientRegId1>NH0000412006</patientRegId1> - <episodeNo No="1"> <visitNo>2</visitNo> <consultantId>5</consultantId> </episodeNo> </PatientID> </NewDataSet> this is my code Dim SqlDataAdapter2 As New SqlDataAdapter(qry, sqlCon) Dim ds As New DataSet SqlDataAdapter2.Fill(ds, "PatientID") ds.WriteXml("E:\\ss.xml") Thanks in Advance
modified on Thursday, January 03, 2008 2:29:20 AM
I am guessing that you have more than one episode per patient and more than one visit per episode. You can always write your own filter to create the XmlDocument you need by iterating through the rows and adding the appropriate nodes to the XmlDocument. Then you can call the Write() method of the XmlDocument. Volker Weichert
-
I am guessing that you have more than one episode per patient and more than one visit per episode. You can always write your own filter to create the XmlDocument you need by iterating through the rows and adding the appropriate nodes to the XmlDocument. Then you can call the Write() method of the XmlDocument. Volker Weichert
-
Yes you are right... but i dont know how to write node by node using Dataset.. pelase can u help me
Try something like this:
Dim doc As XmlDocument = New XmlDocument()
Dim tableName As String = "myTable"
Dim node, attrib As XmlNode
Dim parentNode As XmlNode = doc.DocumentElement
For Each row As DataRow In ds.Tables(tableName).rows
node = doc.CreateNode(XmlNodeType.Element, "myElement", myNameSpaceURI)
attrib = doc.CreateAttribute("myAttribute")
attrib.Value = row("myAttributeColumn").ToString()
node.Attributes.Append(attrib)
parentNode.AppendChild(node)
NextYou just need to adjust this to fit your own table. Volker Weichert