本文整理汇总了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