XmlParserContext Konstruktory

Definicja

Inicjuje XmlParserContext nowe wystąpienie klasy z określonymi wartościami.

Przeciążenia

XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace)

Inicjuje XmlParserContext nowe wystąpienie klasy z określonymi XmlNameTablewartościami , XmlNamespaceManager, xml:langi xml:space .

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

Inicjuje XmlParserContext nowe wystąpienie klasy z określonym XmlNameTable, , XmlNamespaceManagerxml:lang, xml:spacei kodowaniem.

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

Inicjuje XmlParserContext nowe wystąpienie klasy z określonymi XmlNameTablewartościami typu , XmlNamespaceManager, identyfikator URI podstawowy, xml:spacexml:langi dokument.

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

Inicjuje XmlParserContext nowe wystąpienie klasy z określonymi XmlNameTablewartościami typu , , XmlNamespaceManagerbase URI, xml:lang, xml:spacekodowanie i dokument.

XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace)

Inicjuje XmlParserContext nowe wystąpienie klasy z określonymi XmlNameTablewartościami , XmlNamespaceManager, xml:langi xml:space .

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)

Parametry

nt
XmlNameTable

Element XmlNameTable do użycia do atomizowania ciągów. Jeśli jest nullto , zamiast tego jest używana tabela nazw używana do konstruowania obiektu nsMgr . Aby uzyskać więcej informacji na temat atomizowanych ciągów, zobacz XmlNameTable.

nsMgr
XmlNamespaceManager

Element XmlNamespaceManager do użycia do wyszukiwania informacji o przestrzeni nazw lub null.

xmlLang
String

Zakres xml:lang .

xmlSpace
XmlSpace

Wartość wskazująca XmlSpace xml:space zakres.

Wyjątki

nt nie jest tym samym XmlNameTable używanym do konstruowania nsMgr.

Przykłady

Poniższy przykład odczytuje fragment XML. Używa elementu XmlParserContext i do XmlNamespaceManager obsługi dopasowywania przestrzeni nazw.

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

Dotyczy

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

Inicjuje XmlParserContext nowe wystąpienie klasy z określonym XmlNameTable, , XmlNamespaceManagerxml:lang, xml:spacei kodowaniem.

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)

Parametry

nt
XmlNameTable

Element XmlNameTable do użycia do atomizowania ciągów. Jeśli jest nullto , zamiast tego jest używana tabela nazw używana do konstruowania obiektu nsMgr . Aby uzyskać więcej informacji na temat ciągów atomizowanych, zobacz XmlNameTable.

nsMgr
XmlNamespaceManager

Element XmlNamespaceManager do użycia do wyszukiwania informacji o przestrzeni nazw lub null.

xmlLang
String

Zakres xml:lang .

xmlSpace
XmlSpace

Wartość wskazująca XmlSpace xml:space zakres.

enc
Encoding

Encoding Obiekt wskazujący ustawienie kodowania.

Wyjątki

nt nie jest tym samym XmlNameTable używanym do konstruowania nsMgr.

Dotyczy

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

Inicjuje XmlParserContext nowe wystąpienie klasy z określonymi XmlNameTablewartościami typu , XmlNamespaceManager, identyfikator URI podstawowy, xml:spacexml:langi dokument.

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)

Parametry

nt
XmlNameTable

Element XmlNameTable do użycia do atomizowania ciągów. Jeśli jest nullto , zamiast tego jest używana tabela nazw używana do konstruowania obiektu nsMgr . Aby uzyskać więcej informacji na temat atomizowanych ciągów, zobacz XmlNameTable.

nsMgr
XmlNamespaceManager

Element XmlNamespaceManager do użycia do wyszukiwania informacji o przestrzeni nazw lub null.

docTypeName
String

Nazwa deklaracji typu dokumentu.

pubId
String

Identyfikator publiczny.

sysId
String

Identyfikator systemu.

internalSubset
String

Wewnętrzny podzestaw DTD. Podzestaw DTD jest używany do rozpoznawania jednostek, a nie do sprawdzania poprawności dokumentu.

baseURI
String

Podstawowy identyfikator URI fragmentu XML (lokalizacja, z której załadowano fragment).

xmlLang
String

Zakres xml:lang .

xmlSpace
XmlSpace

Wartość wskazująca XmlSpace xml:space zakres.

Wyjątki

nt nie jest tym samym XmlNameTable używanym do konstruowania nsMgr.

Przykłady

W poniższym przykładzie użyto elementu do XmlParserContext odczytania fragmentu XML.

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

Uwagi

Ten konstruktor dostarcza wszystkie DocumentType informacje wymagane przez XmlValidatingReaderprogram . Jeśli jest to XmlParserContext przekazywane do elementu XmlTextReader, wszystkie informacje DTD są ignorowane.

Jeśli przekazujesz dtD jako internalSubset, dtD jest używany do rozpoznawania jednostek, a nie do sprawdzania poprawności dokumentu.

Dotyczy

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

Inicjuje XmlParserContext nowe wystąpienie klasy z określonymi XmlNameTablewartościami typu , , XmlNamespaceManagerbase URI, xml:lang, xml:spacekodowanie i dokument.

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)

Parametry

nt
XmlNameTable

Element XmlNameTable do użycia do atomizowania ciągów. Jeśli jest nullto , zamiast tego jest używana tabela nazw używana do konstruowania obiektu nsMgr . Aby uzyskać więcej informacji na temat atomizowanych ciągów, zobacz XmlNameTable.

nsMgr
XmlNamespaceManager

Element XmlNamespaceManager do użycia do wyszukiwania informacji o przestrzeni nazw lub null.

docTypeName
String

Nazwa deklaracji typu dokumentu.

pubId
String

Identyfikator publiczny.

sysId
String

Identyfikator systemu.

internalSubset
String

Wewnętrzny podzestaw DTD. DtD jest używany do rozpoznawania jednostek, a nie do sprawdzania poprawności dokumentu.

baseURI
String

Podstawowy identyfikator URI fragmentu XML (lokalizacja, z której załadowano fragment).

xmlLang
String

Zakres xml:lang .

xmlSpace
XmlSpace

Wartość wskazująca XmlSpace xml:space zakres.

enc
Encoding

Encoding Obiekt wskazujący ustawienie kodowania.

Wyjątki

nt nie jest tym samym XmlNameTable używanym do konstruowania nsMgr.

Dotyczy