XmlParserContext Construtores

Definição

Inicializa uma nova instância da XmlParserContext classe com os valores especificados.

Sobrecargas

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

Inicializa uma nova instância da XmlParserContext classe com os valores especificados XmlNameTable, XmlNamespaceManager, xml:lang, e xml:space .

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

Inicializa uma nova instância da XmlParserContext classe com a codificação especificada XmlNameTable, XmlNamespaceManager, xml:lang, xml:space, e .

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

Inicializa uma nova instância da XmlParserContext classe com os valores especificados XmlNameTable, XmlNamespaceManager, URI base, xml:lang, xml:space, e tipo de documento.

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

Inicializa uma nova instância da XmlParserContext classe com os valores especificados XmlNameTable, XmlNamespaceManager, base URI, xml:lang, xml:space, codificação e tipo de documento.

XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace)

Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs

Inicializa uma nova instância da XmlParserContext classe com os valores especificados XmlNameTable, XmlNamespaceManager, xml:lang, e 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)

Parâmetros

nt
XmlNameTable

A XmlNameTable usar para atomizar cordas. Se isto for null, a tabela de nomes usada para construir o nsMgr é usada em vez disso. Para mais informações sobre cordas atomizadas, veja XmlNameTable.

nsMgr
XmlNamespaceManager

O XmlNamespaceManager para usar para procurar informação de namespace, ou null.

xmlLang
String

A xml:lang mira.

xmlSpace
XmlSpace

Um valor que XmlSpace indica o xml:space âmbito.

Exceções

nt não é o mesmo XmlNameTable usado para construir nsMgr.

Exemplos

O exemplo seguinte lê um fragmento XML. Usa um XmlParserContext and its XmlNamespaceManager para gerir a correspondência de namespace.

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

Aplica-se a

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

Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs

Inicializa uma nova instância da XmlParserContext classe com a codificação especificada XmlNameTable, XmlNamespaceManager, xml:lang, xml:space, e .

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)

Parâmetros

nt
XmlNameTable

A XmlNameTable usar para atomizar cordas. Se isto for null, a tabela de nomes usada para construir o nsMgr é usada em vez disso. Para mais informações sobre cordas atomizadas, veja XmlNameTable.

nsMgr
XmlNamespaceManager

O XmlNamespaceManager para usar para procurar informação de namespace, ou null.

xmlLang
String

A xml:lang mira.

xmlSpace
XmlSpace

Um valor que XmlSpace indica o xml:space âmbito.

enc
Encoding

Um objeto que Encoding indica a definição de codificação.

Exceções

nt não é o mesmo XmlNameTable usado para construir nsMgr.

Aplica-se a

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

Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs

Inicializa uma nova instância da XmlParserContext classe com os valores especificados XmlNameTable, XmlNamespaceManager, URI base, xml:lang, xml:space, e tipo de documento.

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)

Parâmetros

nt
XmlNameTable

A XmlNameTable usar para atomizar cordas. Se isto for null, a tabela de nomes usada para construir o nsMgr é usada em vez disso. Para mais informações sobre cordas atomizadas, veja XmlNameTable.

nsMgr
XmlNamespaceManager

O XmlNamespaceManager para usar para procurar informação de namespace, ou null.

docTypeName
String

O nome do tipo de declaração do documento.

pubId
String

O identificador público.

sysId
String

O identificador do sistema.

internalSubset
String

O subconjunto interno DTD. O subconjunto DTD é usado para resolução de entidades, não para validação de documentos.

baseURI
String

O URI base do fragmento XML (a localização de onde o fragmento foi carregado).

xmlLang
String

A xml:lang mira.

xmlSpace
XmlSpace

Um valor que XmlSpace indica o xml:space âmbito.

Exceções

nt não é o mesmo XmlNameTable usado para construir nsMgr.

Exemplos

O exemplo seguinte utiliza um XmlParserContext para ler um fragmento 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

Observações

Este construtor fornece toda a DocumentType informação necessária por XmlValidatingReader. Se isto XmlParserContext for passado para um XmlTextReader, toda a informação DTD é ignorada.

Se passar um DTD como o internalSubset, o DTD é usado para resolução de entidades, não para validação de documentos.

Aplica-se a

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

Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs
Origem:
XmlParserContext.cs

Inicializa uma nova instância da XmlParserContext classe com os valores especificados XmlNameTable, XmlNamespaceManager, base URI, xml:lang, xml:space, codificação e tipo de documento.

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)

Parâmetros

nt
XmlNameTable

A XmlNameTable usar para atomizar cordas. Se isto for null, a tabela de nomes usada para construir o nsMgr é usada em vez disso. Para mais informações sobre cordas atomizadas, veja XmlNameTable.

nsMgr
XmlNamespaceManager

O XmlNamespaceManager para usar para procurar informação de namespace, ou null.

docTypeName
String

O nome do tipo de declaração do documento.

pubId
String

O identificador público.

sysId
String

O identificador do sistema.

internalSubset
String

O subconjunto interno DTD. O DTD é usado para resolução de entidades, não para validação de documentos.

baseURI
String

O URI base do fragmento XML (a localização de onde o fragmento foi carregado).

xmlLang
String

A xml:lang mira.

xmlSpace
XmlSpace

Um valor que XmlSpace indica o xml:space âmbito.

enc
Encoding

Um objeto que Encoding indica a definição de codificação.

Exceções

nt não é o mesmo XmlNameTable usado para construir nsMgr.

Aplica-se a