本文整理匯總了VB.NET中System.Xml.XmlTextReader.XmlTextReader構造函數的典型用法代碼示例。如果您正苦於以下問題:VB.NET XmlTextReader構造函數的具體用法?VB.NET XmlTextReader怎麽用?VB.NET XmlTextReader使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在類System.Xml.XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader構造函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Main
' 導入命名空間
Imports System.IO
Imports System.Xml
public class Sample
public shared sub Main()
'Create the XML fragment to be parsed.
Dim xmlFrag as string ="<book> " & _
"<title>Pride And Prejudice</title>" & _
"<bk:genre>novel</bk:genre>" & _
"</book>"
'Create the XmlNamespaceManager.
Dim nt as NameTable = new NameTable()
Dim nsmgr as XmlNamespaceManager = new XmlNamespaceManager(nt)
nsmgr.AddNamespace("bk", "urn:sample")
'Create the XmlParserContext.
Dim context as XmlParserContext = new XmlParserContext(nothing, nsmgr, nothing, XmlSpace.None)
'Create the reader.
Dim reader as XmlTextReader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context)
'Parse the XML. If they exist, display the prefix and
'namespace URI of each element.
while (reader.Read())
if (reader.IsStartElement())
if (reader.Prefix=String.Empty)
Console.WriteLine("<{0}>", reader.LocalName)
else
Console.Write("<{0}:{1}>", reader.Prefix, reader.LocalName)
Console.WriteLine(" The namespace URI is " + reader.NamespaceURI)
end if
end if
end while
'Close the reader.
reader.Close()
end sub
end class
示例2: Sample
Option Strict
Option Explicit
Imports System.IO
Imports System.Xml
'Reads an XML document
Public Class Sample
Private Const filename As String = "items.xml"
Public Shared Sub Main()
Dim reader As XmlTextReader = Nothing
Try
' Load the reader with the data file and ignore all white space nodes.
reader = New XmlTextReader(filename)
reader.WhitespaceHandling = WhitespaceHandling.None
' Parse the file and display each of the nodes.
While reader.Read()
Select Case reader.NodeType
Case XmlNodeType.Element
Console.Write("<{0}>", reader.Name)
Case XmlNodeType.Text
Console.Write(reader.Value)
Case XmlNodeType.CDATA
Console.Write("<![CDATA[{0}]]>", reader.Value)
Case XmlNodeType.ProcessingInstruction
Console.Write("<?{0} {1}?>", reader.Name, reader.Value)
Case XmlNodeType.Comment
Console.Write("<!--{0}-->", reader.Value)
Case XmlNodeType.XmlDeclaration
Console.Write("<?xml version='1.0'?>")
Case XmlNodeType.Document
Case XmlNodeType.DocumentType
Console.Write("<!DOCTYPE {0} [{1}]", reader.Name, reader.Value)
Case XmlNodeType.EntityReference
Console.Write(reader.Name)
Case XmlNodeType.EndElement
Console.Write("</{0}>", reader.Name)
End Select
End While
Finally
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub
End Class
示例3: Main
' 導入命名空間
Imports System.IO
Imports System.Xml
public class Sample
public shared sub Main()
Dim xmlData as string
xmlData = "<book>" & _
" <title>Oberon's Legacy</title>" & _
" <price>5.95</price>" & _
"</book>"
' Create the reader.
Dim reader as XmlTextReader = new XmlTextReader(new StringReader(xmlData))
reader.WhitespaceHandling = WhitespaceHandling.None
' Display each element node.
while reader.Read()
select case reader.NodeType
case XmlNodeType.Element
Console.Write("<{0}>", reader.Name)
case XmlNodeType.Text
Console.Write(reader.Value)
case XmlNodeType.EndElement
Console.Write("</{0}>", reader.Name)
end select
end while
' Close the reader.
reader.Close()
end sub
end class