XmlParserContext Costruttori

Definizione

Inizializza una nuova istanza della XmlParserContext classe con i valori specificati.

Overload

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

Inizializza una nuova istanza della XmlParserContext classe con i valori , XmlNameTable, XmlNamespaceManagere xml:lang specificatixml:space.

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

Inizializza una nuova istanza della XmlParserContext classe con la codifica , , XmlNameTableXmlNamespaceManagerxml:lang, e specificata.xml:space

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

Inizializza una nuova istanza della XmlParserContext classe con i valori del tipo di documento , , XmlNameTable, XmlNamespaceManagerxml:lang, , e specificatixml:space.

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

Inizializza una nuova istanza della XmlParserContext classe con i XmlNameTablevalori specificati, , XmlNamespaceManagerURI di base, xml:lang, xml:space, codifica e tipo di documento.

XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace)

Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs

Inizializza una nuova istanza della XmlParserContext classe con i valori , XmlNameTable, XmlNamespaceManagere xml:lang specificatixml: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)

Parametri

nt
XmlNameTable

Oggetto XmlNameTable da utilizzare per atomizzare le stringhe. Se si tratta di null, viene utilizzata la tabella dei nomi utilizzata per costruire l'oggetto nsMgr . Per altre informazioni sulle stringhe atomizzate, vedere XmlNameTable.

nsMgr
XmlNamespaceManager

Oggetto XmlNamespaceManager da usare per la ricerca di informazioni sullo spazio dei nomi o null.

xmlLang
String

Ambito xml:lang .

xmlSpace
XmlSpace

Valore XmlSpace che indica l'ambito xml:space .

Eccezioni

nt non è lo stesso XmlNameTable utilizzato per costruire nsMgr.

Esempio

Nell'esempio seguente viene letto un frammento XML. Usa un oggetto XmlParserContext e il relativo XmlNamespaceManager per gestire la corrispondenza dello spazio dei nomi.

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

Si applica a

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

Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs

Inizializza una nuova istanza della XmlParserContext classe con la codifica , , XmlNameTableXmlNamespaceManagerxml:lang, e specificata.xml:space

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)

Parametri

nt
XmlNameTable

Oggetto XmlNameTable da utilizzare per atomizzare le stringhe. Se si tratta di null, viene utilizzata la tabella dei nomi utilizzata per costruire l'oggetto nsMgr . Per altre informazioni sulle stringhe atomizzate, vedere XmlNameTable.

nsMgr
XmlNamespaceManager

Oggetto XmlNamespaceManager da usare per la ricerca di informazioni sullo spazio dei nomi o null.

xmlLang
String

Ambito xml:lang .

xmlSpace
XmlSpace

Valore XmlSpace che indica l'ambito xml:space .

enc
Encoding

Oggetto Encoding che indica l'impostazione di codifica.

Eccezioni

nt non è lo stesso XmlNameTable utilizzato per costruire nsMgr.

Si applica a

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

Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs

Inizializza una nuova istanza della XmlParserContext classe con i valori del tipo di documento , , XmlNameTable, XmlNamespaceManagerxml:lang, , e specificatixml:space.

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)

Parametri

nt
XmlNameTable

Oggetto XmlNameTable da utilizzare per atomizzare le stringhe. Se si tratta di null, viene utilizzata la tabella dei nomi utilizzata per costruire l'oggetto nsMgr . Per altre informazioni sulle stringhe atomizzate, vedere XmlNameTable.

nsMgr
XmlNamespaceManager

Oggetto XmlNamespaceManager da usare per la ricerca di informazioni sullo spazio dei nomi o null.

docTypeName
String

Nome della dichiarazione del tipo di documento.

pubId
String

Identificatore pubblico.

sysId
String

Identificatore di sistema.

internalSubset
String

Subset DTD interno. Il subset DTD viene usato per la risoluzione delle entità, non per la convalida del documento.

baseURI
String

URI di base per il frammento XML (posizione da cui è stato caricato il frammento).

xmlLang
String

Ambito xml:lang .

xmlSpace
XmlSpace

Valore XmlSpace che indica l'ambito xml:space .

Eccezioni

nt non è lo stesso XmlNameTable utilizzato per costruire nsMgr.

Esempio

Nell'esempio seguente viene utilizzato un oggetto XmlParserContext per leggere un frammento 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

Commenti

Questo costruttore fornisce tutte le DocumentType informazioni richieste da XmlValidatingReader. Se viene XmlParserContext passato a un XmlTextReaderoggetto , tutte le informazioni DTD vengono ignorate.

Se si passa un DTD come internalSubset, il DTD viene usato per la risoluzione delle entità, non per la convalida dei documenti.

Si applica a

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

Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs
Origine:
XmlParserContext.cs

Inizializza una nuova istanza della XmlParserContext classe con i XmlNameTablevalori specificati, , XmlNamespaceManagerURI di base, xml:lang, xml:space, codifica e tipo di 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)

Parametri

nt
XmlNameTable

Oggetto XmlNameTable da utilizzare per atomizzare le stringhe. Se si tratta di null, viene utilizzata la tabella dei nomi utilizzata per costruire l'oggetto nsMgr . Per altre informazioni sulle stringhe atomizzate, vedere XmlNameTable.

nsMgr
XmlNamespaceManager

Oggetto XmlNamespaceManager da usare per la ricerca di informazioni sullo spazio dei nomi o null.

docTypeName
String

Nome della dichiarazione del tipo di documento.

pubId
String

Identificatore pubblico.

sysId
String

Identificatore di sistema.

internalSubset
String

Subset DTD interno. Il DTD viene usato per la risoluzione delle entità, non per la convalida del documento.

baseURI
String

URI di base per il frammento XML (posizione da cui è stato caricato il frammento).

xmlLang
String

Ambito xml:lang .

xmlSpace
XmlSpace

Valore XmlSpace che indica l'ambito xml:space .

enc
Encoding

Oggetto Encoding che indica l'impostazione di codifica.

Eccezioni

nt non è lo stesso XmlNameTable utilizzato per costruire nsMgr.

Si applica a