Create XmlTextReader class with the specified string, XmlNodeType, and XmlParserContext. : XmlNode « XML « VB.Net






Create XmlTextReader class with the specified string, XmlNodeType, and XmlParserContext.

 

Imports System
Imports System.IO
Imports System.Xml

public class Sample 
  public shared sub Main()
    Dim xmlFrag as string ="<book> " & _
                           "<title>C#</title>" & _
                           "<bk:genre>Computer</bk:genre>" & _
                           "</book>" 

    Dim nt as NameTable = new NameTable()
    Dim nsmgr as XmlNamespaceManager = new XmlNamespaceManager(nt)
    nsmgr.AddNamespace("bk", "urn:sample")

    Dim context as XmlParserContext = new XmlParserContext(nothing, nsmgr, nothing, XmlSpace.None)

    Dim reader as XmlTextReader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context)

    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
    reader.Close()     

  end sub
end class

   
  








Related examples in the same category

1.Creates an XmlNode with the specified node type, Name, and NamespaceURI.
2.Creates an XmlNode with the specified XmlNodeType, Name, and NamespaceURI.
3.Creates a XmlNode with the specified XmlNodeType, Prefix, Name, and NamespaceURI.
4.Returns an XmlNodeList containing a list of all descendant elements that match the specified Name.
5.Creates XmlNode based on the information in XmlReader
6.Returns an XmlNodeList containing a list of all descendant elements that match the specified Name.
7.XmlNode.CloneNode creates a duplicate of the node.
8.Provides support for the for each style iteration over the nodes in the XmlNode.
9.XmlNode.GetPrefixOfNamespace
10.XmlNode.InsertAfter inserts the specified node immediately after the specified reference node.
11.XmlNode.InsertBefore inserts the specified node immediately before the specified reference node.
12.XmlNode.Item gets the first child element with the specified Name.
13.XmlNode.LastChild gets the last child of the node.
14.XmlNode.NextSibling gets the node immediately following this node.
15.XmlNode.SelectNodes Method (String, XmlNamespaceManager)
16.Selects the first XmlNode that matches the XPath expression.
17.XmlNode.SelectSingleNode Method (String, XmlNamespaceManager)
18.XmlNode.WriteContentTo saves all the child nodes of the node to the specified XmlWriter.
19.XmlNode.WriteTo saves the current node to the specified XmlWriter.