本文整理匯總了VB.NET中System.Xml.XmlNamespaceManager.AddNamespace方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET XmlNamespaceManager.AddNamespace方法的具體用法?VB.NET XmlNamespaceManager.AddNamespace怎麽用?VB.NET XmlNamespaceManager.AddNamespace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。
在下文中一共展示了XmlNamespaceManager.AddNamespace方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Sample
' 導入命名空間
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
Dim reader As XmlTextReader = Nothing
Try
' Create the string containing the XML to read.
Dim xmlFrag As String
xmlFrag = "<book>" & _
"<title>Pride And Prejudice</title>" & _
"<author>" & _
"<first-name>Jane</first-name>" & _
"<last-name>Austen</last-name>" & _
"</author>" & _
"<curr:price>19.95</curr:price>" & _
"<misc>&h;</misc>" & _
"</book>"
' Create an XmlNamespaceManager to resolve namespaces.
Dim nt As NameTable = New NameTable()
Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(nt)
nsmgr.AddNamespace(String.Empty, "urn:samples") 'default namespace
nsmgr.AddNamespace("curr", "urn:samples:dollar")
' Create an XmlParserContext. The XmlParserContext contains all the information
' required to parse the XML fragment, including the entity information and the
' XmlNamespaceManager to use for namespace resolution.
Dim context As XmlParserContext
Dim subset As String = "<!ENTITY h 'hardcover'>"
context = New XmlParserContext(nt, nsmgr, "book", Nothing, Nothing, subset, Nothing, Nothing, XmlSpace.None)
' Create the reader.
reader = New XmlTextReader(xmlFrag, XmlNodeType.Element, context)
' Parse the file and display the node values.
While (reader.Read())
If (reader.HasValue) Then
Console.WriteLine("{0} [{1}] = {2}", reader.NodeType, reader.Name, reader.Value)
Else
Console.WriteLine("{0} [{1}]", reader.NodeType, reader.Name)
End If
End While
Finally
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub
End Class