XmlParserContext Constructors
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the XmlParserContext
class with the specified values.
XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace) |
Initializes a new instance of the |
XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace, Encoding) |
Initializes a new instance of the |
XmlParserContext(XmlNameTable, XmlNamespaceManager, String, String, String, String, String, String, XmlSpace) |
Initializes a new instance of the |
XmlParserContext(XmlNameTable, XmlNamespaceManager, String, String, String, String, String, String, XmlSpace, Encoding) |
Initializes a new instance of the |
- 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, 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)
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.
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
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
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 |
- 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, 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)
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.
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, 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)
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.
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
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
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, 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)
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.
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 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: