संपादित करें

इसके माध्यम से साझा किया गया


XmlParserContext Constructors

Definition

Initializes a new instance of the XmlParserContext class with the specified values.

Overloads

XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace)

Initializes a new instance of the XmlParserContext class with the specified XmlNameTable, XmlNamespaceManager, xml:lang, and xml:space values.

XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace, Encoding)

Initializes a new instance of the XmlParserContext class with the specified XmlNameTable, XmlNamespaceManager, xml:lang, xml:space, and encoding.

XmlParserContext(XmlNameTable, XmlNamespaceManager, String, String, String, String, String, String, XmlSpace)

Initializes a new instance of the XmlParserContext class with the specified XmlNameTable, XmlNamespaceManager, base URI, xml:lang, xml:space, and document type values.

XmlParserContext(XmlNameTable, XmlNamespaceManager, String, String, String, String, String, String, XmlSpace, Encoding)

Initializes a new instance of the XmlParserContext class with the specified XmlNameTable, XmlNamespaceManager, base URI, xml:lang, xml:space, encoding, and document type values.

XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace)

Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs

Initializes a new instance of the XmlParserContext class with the specified XmlNameTable, XmlNamespaceManager, xml:lang, and xml:space values.

public:
 XmlParserContext(System::Xml::XmlNameTable ^ nt, System::Xml::XmlNamespaceManager ^ nsMgr, System::String ^ xmlLang, System::Xml::XmlSpace xmlSpace);
public XmlParserContext (System.Xml.XmlNameTable nt, System.Xml.XmlNamespaceManager nsMgr, string xmlLang, System.Xml.XmlSpace xmlSpace);
public XmlParserContext (System.Xml.XmlNameTable? nt, System.Xml.XmlNamespaceManager? nsMgr, string? xmlLang, System.Xml.XmlSpace xmlSpace);
new System.Xml.XmlParserContext : System.Xml.XmlNameTable * System.Xml.XmlNamespaceManager * string * System.Xml.XmlSpace -> System.Xml.XmlParserContext
Public Sub New (nt As XmlNameTable, nsMgr As XmlNamespaceManager, xmlLang As String, xmlSpace As XmlSpace)

Parameters

nt
XmlNameTable

The XmlNameTable to use to atomize strings. If this is null, the name table used to construct the nsMgr is used instead. For more information about atomized strings, see XmlNameTable.

nsMgr
XmlNamespaceManager

The XmlNamespaceManager to use for looking up namespace information, or null.

xmlLang
String

The xml:lang scope.

xmlSpace
XmlSpace

An XmlSpace value indicating the xml:space scope.

Exceptions

nt is not the same XmlNameTable used to construct nsMgr.

Examples

The following example reads an XML fragment. It uses an XmlParserContext and its XmlNamespaceManager to handle namespace matching.

using System;
using System.IO;
using System.Xml;

public class Sample
{
    public static void Main()
    {
        XmlTextReader reader = null;

        try
        {
            //Create the XML fragment to be parsed.
            string xmlFrag = "<book> " +
                            "<title>Pride And Prejudice</title>" +
                            "<bk:genre>novel</bk:genre>" +
                            "</book>";

            //Create the XmlNamespaceManager that is used to
            //look up namespace information.
            NameTable nt = new NameTable();
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
            nsmgr.AddNamespace("bk", "urn:sample");

            //Create the XmlParserContext.
            XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);

            //Implement the reader.
            reader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context);

            //Parse the XML fragment.  If they exist, display the
            //prefix and namespace URI of each element.
            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    if (string.IsNullOrEmpty(reader.Prefix))
                    {
                        Console.WriteLine("<{0}>", reader.LocalName);
                    }
                    else
                    {
                        Console.Write("<{0}:{1}>", reader.Prefix, reader.LocalName);
                        Console.WriteLine(" The namespace URI is " + reader.NamespaceURI);
                    }
                }
            }
        }

        finally
        {
            if (reader != null)
                reader.Close();
        }
    }
} // End class
Imports System.IO
Imports System.Xml

Public Class Sample

    Public Shared Sub Main()
        Dim reader As XmlTextReader = Nothing

        Try
            '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 that is used to
            'look up namespace information.
            Dim nt As New NameTable()
            Dim nsmgr As New XmlNamespaceManager(nt)
            nsmgr.AddNamespace("bk", "urn:sample")

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

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

            'Parse the XML fragment.  If they exist, display the   
            'prefix and namespace URI of each element.
            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
        Finally
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
    End Sub
End Class

Applies to

XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace, Encoding)

Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs

Initializes a new instance of the XmlParserContext class with the specified XmlNameTable, XmlNamespaceManager, xml:lang, xml:space, and encoding.

public:
 XmlParserContext(System::Xml::XmlNameTable ^ nt, System::Xml::XmlNamespaceManager ^ nsMgr, System::String ^ xmlLang, System::Xml::XmlSpace xmlSpace, System::Text::Encoding ^ enc);
public XmlParserContext (System.Xml.XmlNameTable nt, System.Xml.XmlNamespaceManager nsMgr, string xmlLang, System.Xml.XmlSpace xmlSpace, System.Text.Encoding enc);
public XmlParserContext (System.Xml.XmlNameTable? nt, System.Xml.XmlNamespaceManager? nsMgr, string? xmlLang, System.Xml.XmlSpace xmlSpace, System.Text.Encoding? enc);
new System.Xml.XmlParserContext : System.Xml.XmlNameTable * System.Xml.XmlNamespaceManager * string * System.Xml.XmlSpace * System.Text.Encoding -> System.Xml.XmlParserContext
Public Sub New (nt As XmlNameTable, nsMgr As XmlNamespaceManager, xmlLang As String, xmlSpace As XmlSpace, enc As Encoding)

Parameters

nt
XmlNameTable

The XmlNameTable to use to atomize strings. If this is null, the name table used to construct the nsMgr is used instead. For more information on atomized strings, see XmlNameTable.

nsMgr
XmlNamespaceManager

The XmlNamespaceManager to use for looking up namespace information, or null.

xmlLang
String

The xml:lang scope.

xmlSpace
XmlSpace

An XmlSpace value indicating the xml:space scope.

enc
Encoding

An Encoding object indicating the encoding setting.

Exceptions

nt is not the same XmlNameTable used to construct nsMgr.

Applies to

XmlParserContext(XmlNameTable, XmlNamespaceManager, String, String, String, String, String, String, XmlSpace)

Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs

Initializes a new instance of the XmlParserContext class with the specified XmlNameTable, XmlNamespaceManager, base URI, xml:lang, xml:space, and document type values.

public:
 XmlParserContext(System::Xml::XmlNameTable ^ nt, System::Xml::XmlNamespaceManager ^ nsMgr, System::String ^ docTypeName, System::String ^ pubId, System::String ^ sysId, System::String ^ internalSubset, System::String ^ baseURI, System::String ^ xmlLang, System::Xml::XmlSpace xmlSpace);
public XmlParserContext (System.Xml.XmlNameTable nt, System.Xml.XmlNamespaceManager nsMgr, string docTypeName, string pubId, string sysId, string internalSubset, string baseURI, string xmlLang, System.Xml.XmlSpace xmlSpace);
public XmlParserContext (System.Xml.XmlNameTable? nt, System.Xml.XmlNamespaceManager? nsMgr, string? docTypeName, string? pubId, string? sysId, string? internalSubset, string? baseURI, string? xmlLang, System.Xml.XmlSpace xmlSpace);
new System.Xml.XmlParserContext : System.Xml.XmlNameTable * System.Xml.XmlNamespaceManager * string * string * string * string * string * string * System.Xml.XmlSpace -> System.Xml.XmlParserContext
Public Sub New (nt As XmlNameTable, nsMgr As XmlNamespaceManager, docTypeName As String, pubId As String, sysId As String, internalSubset As String, baseURI As String, xmlLang As String, xmlSpace As XmlSpace)

Parameters

nt
XmlNameTable

The XmlNameTable to use to atomize strings. If this is null, the name table used to construct the nsMgr is used instead. For more information about atomized strings, see XmlNameTable.

nsMgr
XmlNamespaceManager

The XmlNamespaceManager to use for looking up namespace information, or null.

docTypeName
String

The name of the document type declaration.

pubId
String

The public identifier.

sysId
String

The system identifier.

internalSubset
String

The internal DTD subset. The DTD subset is used for entity resolution, not for document validation.

baseURI
String

The base URI for the XML fragment (the location from which the fragment was loaded).

xmlLang
String

The xml:lang scope.

xmlSpace
XmlSpace

An XmlSpace value indicating the xml:space scope.

Exceptions

nt is not the same XmlNameTable used to construct nsMgr.

Examples

The following example uses an XmlParserContext to read an XML fragment.

using System;
using System.IO;
using System.Xml;

public class Sample
{
    public static void Main()
    {
        XmlTextReader reader = null;

        try
        {
            //Create the XML fragment to be parsed.
            string xmlFrag = "<book genre='novel' misc='sale-item &h;'></book>";

            //Create the XmlParserContext. The XmlParserContext provides the
            //necessary DTD information so that the entity reference can be expanded.
            XmlParserContext context;
            string subset = "<!ENTITY h 'hardcover'>";
            context = new XmlParserContext(null, null, "book", null, null, subset, "", "", XmlSpace.None);

            //Create the reader.
            reader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context);

            //Read the all the attributes on the book element.
            reader.MoveToContent();
            while (reader.MoveToNextAttribute())
            {
                Console.WriteLine("{0} = {1}", reader.Name, reader.Value);
            }
        }
        finally
        {
            if (reader != null)
                reader.Close();
        }
    }
} // End class
Option Explicit On
Option Strict On

Imports System.IO
Imports System.Xml

Public Class Sample

    Public Shared Sub Main()
        Dim reader As XmlTextReader = Nothing
        Try
            'Create the XML fragment to be parsed.
            Dim xmlFrag As String = "<book genre='novel' misc='sale-item &h;'></book>"

            'Create the XmlParserContext. The XmlParserContext provides the 
            'necessary DTD information so that the entity reference can be expanded.
            Dim context As XmlParserContext
            Dim subset As String = "<!ENTITY h 'hardcover'>"
            context = New XmlParserContext(Nothing, Nothing, "book", Nothing, Nothing, subset, "", "", XmlSpace.None)

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

            'Read the all the attributes on the book element.
            reader.MoveToContent()
            While reader.MoveToNextAttribute()
                Console.WriteLine("{0} = {1}", reader.Name, reader.Value)
            End While
        Finally
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
    End Sub
End Class

Remarks

This constructor supplies all DocumentType information required by XmlValidatingReader. If this XmlParserContext is passed to an XmlTextReader, all DTD information is ignored.

If you pass a DTD as the internalSubset, the DTD is used for entity resolution, not for document validation.

Applies to

XmlParserContext(XmlNameTable, XmlNamespaceManager, String, String, String, String, String, String, XmlSpace, Encoding)

Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs

Initializes a new instance of the XmlParserContext class with the specified XmlNameTable, XmlNamespaceManager, base URI, xml:lang, xml:space, encoding, and document type values.

public:
 XmlParserContext(System::Xml::XmlNameTable ^ nt, System::Xml::XmlNamespaceManager ^ nsMgr, System::String ^ docTypeName, System::String ^ pubId, System::String ^ sysId, System::String ^ internalSubset, System::String ^ baseURI, System::String ^ xmlLang, System::Xml::XmlSpace xmlSpace, System::Text::Encoding ^ enc);
public XmlParserContext (System.Xml.XmlNameTable nt, System.Xml.XmlNamespaceManager nsMgr, string docTypeName, string pubId, string sysId, string internalSubset, string baseURI, string xmlLang, System.Xml.XmlSpace xmlSpace, System.Text.Encoding enc);
public XmlParserContext (System.Xml.XmlNameTable? nt, System.Xml.XmlNamespaceManager? nsMgr, string? docTypeName, string? pubId, string? sysId, string? internalSubset, string? baseURI, string? xmlLang, System.Xml.XmlSpace xmlSpace, System.Text.Encoding? enc);
new System.Xml.XmlParserContext : System.Xml.XmlNameTable * System.Xml.XmlNamespaceManager * string * string * string * string * string * string * System.Xml.XmlSpace * System.Text.Encoding -> System.Xml.XmlParserContext
Public Sub New (nt As XmlNameTable, nsMgr As XmlNamespaceManager, docTypeName As String, pubId As String, sysId As String, internalSubset As String, baseURI As String, xmlLang As String, xmlSpace As XmlSpace, enc As Encoding)

Parameters

nt
XmlNameTable

The XmlNameTable to use to atomize strings. If this is null, the name table used to construct the nsMgr is used instead. For more information about atomized strings, see XmlNameTable.

nsMgr
XmlNamespaceManager

The XmlNamespaceManager to use for looking up namespace information, or null.

docTypeName
String

The name of the document type declaration.

pubId
String

The public identifier.

sysId
String

The system identifier.

internalSubset
String

The internal DTD subset. The DTD is used for entity resolution, not for document validation.

baseURI
String

The base URI for the XML fragment (the location from which the fragment was loaded).

xmlLang
String

The xml:lang scope.

xmlSpace
XmlSpace

An XmlSpace value indicating the xml:space scope.

enc
Encoding

An Encoding object indicating the encoding setting.

Exceptions

nt is not the same XmlNameTable used to construct nsMgr.

Applies to