.NET Framework Developer's Guide
Reading XML with the XmlReader

The XmlReader class is an abstract base class that provides non-cached, forward-only, read-only access to XML data. It conforms to the W3C Extensible Markup Language (XML) 1.0 and the Namespaces in XML recommendations.

The XmlReader class supports reading XML data from a stream or file. It defines methods and properties that allow you to move through the data and read the contents of a node. The current node refers to the node on which the reader is positioned. The reader is advanced using any of the read methods and properties return the value of the current node.

The XmlReader class enables you to:

  • Verify that the characters are legal XML characters, and that element and attribute names are valid XML names.

  • Verify that the XML document is well formed.

  • Validate the data against a DTD or schema.

  • Retrieve data from the XML stream or skip unwanted records using a pull model.

In This Section

New Features in the XmlReader Class

Describes changes to the XmlReader class.

Common XmlReader Tasks

Describes the most common XmlReader tasks.

Using the XmlReader Class

Describes how to create XmlReader instances, data validation, reading data, and so on.

Comparing XmlReader to SAX Reader

Describes the differences between the XmlReader class and the SAX reader.

Related Sections

Creating XML Readers

Describes how to create XML readers.

Validating XML Data with XmlReader

Describes how to validate data using the XmlReader class.

Security and Your System.Xml Applications

Discusses security issues when working with XML technologies.

See Also

Other Resources

Tags :


Community Content

Thomas Lee
To Read XML File Contents Using XML Reader.


Try
Dim xmlDoc As New XmlDocument()
xmlDoc.Load("D:\\s2.xml")


Dim nodeSource As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/source")
Dim strSource As String = IIf((nodeSource IsNot Nothing), nodeSource.InnerText, String.Empty)
'Console.WriteLine("source: " + strSource)


Dim nodecalogiTransactionRef As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/calogiTransactionRef")

Dim strcalogiTransactionRef As String = IIf((nodecalogiTransactionRef IsNot Nothing), nodecalogiTransactionRef.InnerText, String.Empty)
'Console.WriteLine("calogiTransactionRef: " + strcalogiTransactionRef)

Dim nodedocumentId As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/documentId")
Dim strdocumentId As String = IIf((nodedocumentId IsNot Nothing), nodedocumentId.InnerText, String.Empty)
'Console.WriteLine("documentId: " + strdocumentId)

Dim nodefinancialId As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/financialId")
Dim strfinancialId As String = IIf((nodefinancialId IsNot Nothing), nodefinancialId.InnerText, String.Empty)
'Console.WriteLine("financialId: " + strfinancialId)

Dim nodetransactionId As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/transactionId")
Dim strtransactionId As String = IIf((nodetransactionId IsNot Nothing), nodetransactionId.InnerText, String.Empty)
'Console.WriteLine("transactionId: " + strtransactionId)

Dim nodesubTransactionId As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/subTransactionId")
Dim strsubTransactionId As String = IIf((nodetransactionId IsNot Nothing), nodesubTransactionId.InnerText, String.Empty)

Dim nodechargeCode As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/chargeCode")
Dim strchargeCode As String = IIf((nodetransactionId IsNot Nothing), nodechargeCode.InnerText, String.Empty)

Dim nodelocationCode As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/locationCode")
Dim strlocationCode As String = IIf((nodetransactionId IsNot Nothing), nodelocationCode.InnerText, String.Empty)

Dim nodeaccountUser As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/accountUser")
Dim straccountUser As String = IIf((nodetransactionId IsNot Nothing), nodeaccountUser.InnerText, String.Empty)

Dim nodeamountInBC As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/amountInBC")
Dim strstramountInBC As String = IIf((nodetransactionId IsNot Nothing), nodeamountInBC.InnerText, String.Empty)

Dim nodebaseCurrencyCode As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/baseCurrencyCode")

Dim strbaseCurrencyCode As String = IIf((nodetransactionId IsNot Nothing), nodebaseCurrencyCode.InnerText, String.Empty)
Dim nodeforiegnCurrencyCode As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/foriegnCurrencyCode")

Dim strbaseforiegnCurrencyCode As String = IIf((nodetransactionId IsNot Nothing), nodeforiegnCurrencyCode.InnerText, String.Empty)

Dim nodeexchangeRate As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/exchangeRate")

Dim strbaseexchangeRate As String = IIf((nodetransactionId IsNot Nothing), nodeexchangeRate.InnerText, String.Empty)

Dim nodeaccountCode As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/accountCode")

Dim straccountCode As String = IIf((nodetransactionId IsNot Nothing), nodeaccountCode.InnerText, String.Empty)

Dim nodedateAndTimeBase As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/dateAndTimeBase")

Dim strdateAndTimeBase As String = IIf((nodetransactionId IsNot Nothing), nodedateAndTimeBase.InnerText, String.Empty)

Dim nodedateAndTimeLocal As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/dateAndTimeLocal")

Dim strdateAndTimeLocal As String = IIf((nodetransactionId IsNot Nothing), nodedateAndTimeLocal.InnerText, String.Empty)

Dim nodeaccountingDate As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/accountingDate")

Dim straccountingDate As String = IIf((nodetransactionId IsNot Nothing), nodeaccountingDate.InnerText, String.Empty)

Dim nodetransactingUser As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/transactingUser")

Dim strtransactingUser As String = IIf((nodetransactionId IsNot Nothing), nodetransactingUser.InnerText, String.Empty)

Dim nodeairportCode As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/airportCode")
Dim strairportCode As String = IIf((nodetransactionId IsNot Nothing), nodeairportCode.InnerText, String.Empty)

Dim nodemodeOfPayment As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/modeOfPayment")
Dim strmodeOfPayment As String = IIf((nodetransactionId IsNot Nothing), nodemodeOfPayment.InnerText, String.Empty)

Dim nodeformOfPayment As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/formOfPayment")
Dim strformOfPayment As String = IIf((nodetransactionId IsNot Nothing), nodeformOfPayment.InnerText, String.Empty)

Dim noderemarks As XmlNode = xmlDoc.SelectSingleNode("/transactionRequests/remarks")
Dim strremarks As String = IIf((nodetransactionId IsNot Nothing), noderemarks.InnerText, String.Empty)

Catch ex As Exception
MsgBox(ex.Message)
End Try

Tags : xml using reader

Thomas Lee
Validating special characters in Windows Application Dotnet-2003(sabeer Pasha)
#Region "TextBox Events"
Private Sub txtFinRefNo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtFinRefNo.KeyPress
Try
If Char.IsLetterOrDigit(e.KeyChar) = False And Char.IsControl(e.KeyChar) = False Then
e.Handled = True
End If
Catch ex As Exception
ShowException(ex.Message, MESSAGEBOX_TITLE, ex)
End Try
End Sub
#End Region.
Tags : sample

Page view tracker