Read an XML fragment with XmlParserContext and its XmlNamespaceManager : Namespace « XML « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » XML » Namespace 
25.10.2.Read an XML fragment with XmlParserContext and its XmlNamespaceManager
Imports System
Imports System.IO
Imports System.Xml

Public Class Sample

    Public Shared Sub Main()
        Dim reader As XmlTextReader = Nothing
        Dim xmlFrag As String = "<book> " & _
                                "<title>AAA</title>" & _
                                "<bk:genre>novel</bk:genre>" & _
                                "</book>"

        Dim nt As New NameTable()
        Dim nsmgr As New XmlNamespaceManager(nt)
        nsmgr.AddNamespace("bk""urn:sample")

        Dim context As New XmlParserContext(Nothing, nsmgr, Nothing, XmlSpace.None)

        reader = New XmlTextReader(xmlFrag, XmlNodeType.Element, context)

        While reader.Read()
            If reader.IsStartElement() Then
                If reader.Prefix = String.Empty Then
                    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
    End Sub
End Class
25.10.Namespace
25.10.1.Use the SetContext method to provide an XmlNamespaceManager object for namespace resolution.
25.10.2.Read an XML fragment with XmlParserContext and its XmlNamespaceManager
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.