XmlParserContext 构造函数

定义

使用指定的值初始化类的新实例 XmlParserContext

重载

名称 说明
XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace)

使用指定的、XmlParserContext值和XmlNameTable值初始化类的新实例XmlNamespaceManagerxml:langxml:space

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

使用指定的XmlParserContextXmlNameTableXmlNamespaceManagerxml:lang和编码初始化类的新实例xml:space

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

使用指定的XmlParserContext、基 URI、XmlNameTableXmlNamespaceManager和文档类型值初始化类的新实例xml:langxml:space

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

使用指定的XmlParserContext、基 URI、、XmlNameTable编码XmlNamespaceManager和文档类型值初始化类的新实例xml:langxml:space

XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace)

Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs

使用指定的、XmlParserContext值和XmlNameTable值初始化类的新实例XmlNamespaceManagerxml:langxml: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)

参数

nt
XmlNameTable

XmlNameTable用于原子化字符串。 如果是, null则改用用于构造的名称 nsMgr 表。 有关原子化字符串的详细信息,请参阅 XmlNameTable

nsMgr
XmlNamespaceManager

XmlNamespaceManager用于查找命名空间信息,或 null

xmlLang
String

范围 xml:lang

xmlSpace
XmlSpace

一个 XmlSpace 指示 xml:space 作用域的值。

例外

nt不是用于构造XmlNameTable的相同 nsMgr

示例

以下示例读取 XML 片段。 它使用 a XmlParserContext 及其 XmlNamespaceManager 来处理命名空间匹配。

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

适用于

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

Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs

使用指定的XmlParserContextXmlNameTableXmlNamespaceManagerxml:lang和编码初始化类的新实例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)

参数

nt
XmlNameTable

XmlNameTable用于原子化字符串。 如果是, null则改用用于构造的名称 nsMgr 表。 有关原子化字符串的详细信息,请参阅 XmlNameTable

nsMgr
XmlNamespaceManager

XmlNamespaceManager用于查找命名空间信息,或 null

xmlLang
String

范围 xml:lang

xmlSpace
XmlSpace

一个 XmlSpace 指示 xml:space 作用域的值。

enc
Encoding

指示 Encoding 编码设置的对象。

例外

nt不是用于构造XmlNameTable的相同 nsMgr

适用于

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

Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs

使用指定的XmlParserContext、基 URI、XmlNameTableXmlNamespaceManager和文档类型值初始化类的新实例xml:langxml: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)

参数

nt
XmlNameTable

XmlNameTable用于原子化字符串。 如果是, null则改用用于构造的名称 nsMgr 表。 有关原子化字符串的详细信息,请参阅 XmlNameTable

nsMgr
XmlNamespaceManager

XmlNamespaceManager用于查找命名空间信息,或 null

docTypeName
String

文档类型声明的名称。

pubId
String

公共标识符。

sysId
String

系统标识符。

internalSubset
String

内部 DTD 子集。 DTD 子集用于实体解析,而不是用于文档验证。

baseURI
String

XML 片段的基本 URI(从中加载片段的位置)。

xmlLang
String

范围 xml:lang

xmlSpace
XmlSpace

一个 XmlSpace 指示 xml:space 作用域的值。

例外

nt不是用于构造XmlNameTable的相同 nsMgr

示例

以下示例使用一个 XmlParserContext 读取 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

注解

此构造函数提供所需的DocumentType全部XmlValidatingReader信息。 如果这是 XmlParserContext 传递给 a XmlTextReader,则忽略所有 DTD 信息。

如果作为 DTD 传递,则 DTD internalSubset用于实体解析,而不是用于文档验证。

适用于

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

Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs
Source:
XmlParserContext.cs

使用指定的XmlParserContext、基 URI、、XmlNameTable编码XmlNamespaceManager和文档类型值初始化类的新实例xml:langxml: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, 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)

参数

nt
XmlNameTable

XmlNameTable用于原子化字符串。 如果是, null则改用用于构造的名称 nsMgr 表。 有关原子化字符串的详细信息,请参阅 XmlNameTable

nsMgr
XmlNamespaceManager

XmlNamespaceManager用于查找命名空间信息,或 null

docTypeName
String

文档类型声明的名称。

pubId
String

公共标识符。

sysId
String

系统标识符。

internalSubset
String

内部 DTD 子集。 DTD 用于实体解析,而不是用于文档验证。

baseURI
String

XML 片段的基本 URI(从中加载片段的位置)。

xmlLang
String

范围 xml:lang

xmlSpace
XmlSpace

一个 XmlSpace 指示 xml:space 作用域的值。

enc
Encoding

指示 Encoding 编码设置的对象。

例外

nt不是用于构造XmlNameTable的相同 nsMgr

适用于