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, string xmlLang, System.Xml.XmlSpace xmlSpace);
public XmlParserContext (System.Xml.XmlNameTable? nt, System.Xml.XmlNamespaceManager? nsMgr, string? xmlLang, System.Xml.XmlSpace 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

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

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, 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);

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

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

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, 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);

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

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

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

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, 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);

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

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0