当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET XmlNamespaceManager.AddNamespace方法代码示例

本文整理汇总了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
开发者ID:VB.NET开发者,项目名称:System.Xml,代码行数:55,代码来源:XmlNamespaceManager.AddNamespace


注:本文中的System.Xml.XmlNamespaceManager.AddNamespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。