Share via


XmlParserContext Constructores

Definición

Inicializa una nueva instancia de la clase XmlParserContext con los valores especificados.

Sobrecargas

XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace)

Inicializa una nueva instancia de la clase XmlParserContext con los valores XmlNameTable, XmlNamespaceManager, xml:lang y xml:space especificados.

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

Inicializa una nueva instancia de la clase XmlParserContext con los valores XmlNameTable, XmlNamespaceManager, xml:lang y xml:space especificados y codificación.

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

Inicializa una nueva instancia de la clase XmlParserContext con los valores XmlNameTable, XmlNamespaceManager, URI base, xml:lang, xml:space y tipo de documento especificados.

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

Inicializa una nueva instancia de la clase XmlParserContext con los valores XmlNameTable, XmlNamespaceManager, URI base, xml:lang, xml:space, codificación y tipo de documento especificados.

XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace)

Inicializa una nueva instancia de la clase XmlParserContext con los valores XmlNameTable, XmlNamespaceManager, xml:lang y xml:space especificados.

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

XmlNameTable que se va a utilizar para subdividir cadenas. Si el valor es null, se utilizará la tabla de nombres usada para construir nsMgr. Para obtener más información sobre las cadenas subdivididas, vea XmlNameTable.

nsMgr
XmlNamespaceManager

XmlNamespaceManager que se va a utilizar para buscar información sobre los espacios de nombres o null.

xmlLang
String

El ámbito xml:lang.

xmlSpace
XmlSpace

Valor de XmlSpace que indica el ámbito de xml:space.

Excepciones

nt no es el mismo XmlNameTable utilizado para construir nsMgr.

Ejemplos

En el ejemplo siguiente se lee un fragmento XML. Usa y XmlParserContext para XmlNamespaceManager controlar la coincidencia de espacios de nombres.

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

Se aplica a

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

Inicializa una nueva instancia de la clase XmlParserContext con los valores XmlNameTable, XmlNamespaceManager, xml:lang y xml:space especificados y codificación.

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

XmlNameTable que se va a utilizar para subdividir cadenas. Si el valor es null, se utilizará la tabla de nombres usada para construir nsMgr. Para obtener más información sobre cadenas subdivididas, vea XmlNameTable.

nsMgr
XmlNamespaceManager

XmlNamespaceManager que se va a utilizar para buscar información sobre los espacios de nombres o null.

xmlLang
String

El ámbito xml:lang.

xmlSpace
XmlSpace

Valor de XmlSpace que indica el ámbito de xml:space.

enc
Encoding

Objeto Encoding que indica el valor de codificación.

Excepciones

nt no es el mismo XmlNameTable utilizado para construir nsMgr.

Se aplica a

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

Inicializa una nueva instancia de la clase XmlParserContext con los valores XmlNameTable, XmlNamespaceManager, URI base, xml:lang, xml:space y tipo de documento especificados.

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

XmlNameTable que se va a utilizar para subdividir cadenas. Si el valor es null, se utilizará la tabla de nombres usada para construir nsMgr. Para obtener más información sobre las cadenas subdivididas, vea XmlNameTable.

nsMgr
XmlNamespaceManager

XmlNamespaceManager que se va a utilizar para buscar información sobre los espacios de nombres o null.

docTypeName
String

Nombre de la declaración de tipos de documento.

pubId
String

Identificador público.

sysId
String

Identificador de sistema.

internalSubset
String

Subconjunto DTD interno. El subconjunto DTD se usa para la resolución de entidades, no para la validación de documentos.

baseURI
String

Identificador URI base del fragmento de XML (la ubicación desde la que se cargó el fragmento).

xmlLang
String

El ámbito xml:lang.

xmlSpace
XmlSpace

Valor de XmlSpace que indica el ámbito de xml:space.

Excepciones

nt no es el mismo XmlNameTable utilizado para construir nsMgr.

Ejemplos

En el ejemplo siguiente se usa para XmlParserContext leer un 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

Comentarios

Este constructor proporciona toda la DocumentType información necesaria para XmlValidatingReader. Si se XmlParserContext pasa a , XmlTextReaderse omite toda la información de DTD.

Si pasa un DTD como internalSubset, el DTD se usa para la resolución de entidades, no para la validación de documentos.

Se aplica a

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

Inicializa una nueva instancia de la clase XmlParserContext con los valores XmlNameTable, XmlNamespaceManager, URI base, xml:lang, xml:space, codificación y tipo de documento especificados.

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

XmlNameTable que se va a utilizar para subdividir cadenas. Si el valor es null, se utilizará la tabla de nombres usada para construir nsMgr. Para obtener más información sobre las cadenas subdivididas, vea XmlNameTable.

nsMgr
XmlNamespaceManager

XmlNamespaceManager que se va a utilizar para buscar información sobre los espacios de nombres o null.

docTypeName
String

Nombre de la declaración de tipos de documento.

pubId
String

Identificador público.

sysId
String

Identificador de sistema.

internalSubset
String

Subconjunto DTD interno. DTD se usa para la resolución de entidades, no para la validación de documentos.

baseURI
String

Identificador URI base del fragmento de XML (la ubicación desde la que se cargó el fragmento).

xmlLang
String

El ámbito xml:lang.

xmlSpace
XmlSpace

Valor de XmlSpace que indica el ámbito de xml:space.

enc
Encoding

Objeto Encoding que indica el valor de codificación.

Excepciones

nt no es el mismo XmlNameTable utilizado para construir nsMgr.

Se aplica a