1.11M Members

How to print a report from XML file in VB.NET

 
0
 

I want to print data from XML in readable formate which is the last section of XML file .My code writes data from database to XML file .
Here is a code i use to write XML
Note: myread is a dll containing dataset,data adapter and connection string.
ds As New DataSet

da As New FbDataAdapter

 myRead.myfill("SELECT CODE,DES FROM TB_TEAM a  ORDER BY CODE")
            myRead.ds = New DataSet
            myRead.da.Fill(myRead.ds, "a")
            myRead.ds.WriteXml("C:\Accountant.xml", XmlWriteMode.WriteSchema)

The xml comes in a formate like

<?xml version="1.0" standalone="true"?>

-<NewDataSet>


-<xs:schema xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="" id="NewDataSet">


-<xs:element msdata:UseCurrentLocale="true" msdata:IsDataSet="true" name="NewDataSet">


-<xs:complexType>


-<xs:choice maxOccurs="unbounded" minOccurs="0">


-<xs:element name="a">


-<xs:complexType>


-<xs:sequence>

<xs:element name="VNO" minOccurs="0" type="xs:decimal"/>

<xs:element name="VDATE" minOccurs="0" type="xs:dateTime"/>

<xs:element name="CODE" minOccurs="0" type="xs:string"/>

<xs:element name="SUBHEADOFACCOUNT" minOccurs="0" type="xs:string"/>

<xs:element name="CREDIT" minOccurs="0" type="xs:decimal"/>

<xs:element name="DES" minOccurs="0" type="xs:string"/>

<xs:element name="OCODE" minOccurs="0" type="xs:string"/>

<xs:element name="ODES" minOccurs="0" type="xs:string"/>

<xs:element name="TRID" minOccurs="0" type="xs:decimal"/>

<xs:element name="UID" minOccurs="0" type="xs:string"/>

<xs:element name="ROOM" minOccurs="0" type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:choice>

</xs:complexType>

</xs:element>

</xs:schema>


-<a>

<VNO>1</VNO>

<VDATE>2014-01-10T00:00:00+05:00</VDATE>

<CODE>1020010001</CODE>

<SUBHEADOFACCOUNT>Hafiz Ateeq</SUBHEADOFACCOUNT>

<CREDIT>88</CREDIT>

<DES>seram electrolytes</DES>

<OCODE>1020030003</OCODE>

<ODES>Reception Cash</ODES>

<TRID>1</TRID>

<UID>SALAHUDDIN</UID>

<ROOM>8008</ROOM>

</a>

</NewDataSet>

I want to print the last output section which is
<a>

<VNO>1</VNO>

<VDATE>2014-01-10T00:00:00+05:00</VDATE>

<CODE>1020010001</CODE>

<SUBHEADOFACCOUNT>Hafiz Ateeq</SUBHEADOFACCOUNT>

<CREDIT>88</CREDIT>

<DES>seram electrolytes</DES>

<OCODE>1020030003</OCODE>

<ODES>Reception Cash</ODES>

<TRID>1</TRID>

<UID>SALAHUDDIN</UID>

<ROOM>8008</ROOM>

</a>

How to print this data in a readable format?

 
0
 

Hi,

I'd use an XMLReader to parse the XML and output in whatever format you wish:

Function PrintReport(byref XMLString as String) as String
dim OutPut as String
' Create an XmlReader
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))

'You want to get the XML in the "a" tag
reader.ReadToFollowing("a")
While reader.Read
    Select Case reader.NodeType
        Case XmlNodeType.Element
            OutPut +=  reader.Name &" = "
        Case XmlNodeType.Text
            OutPut +=  reader.Value & CrLf
        Case XmlNodeType.EndElement
               if reader.Name = "a" then
                   Exit While
               End if
    End Select
 End While
 Return OutPut
 End Function
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: