XmlParserContext 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化一個新的類別實例 XmlParserContext ,並以指定值。
多載
| 名稱 | Description |
|---|---|
| XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace) |
初始化一個新的類別實例 |
| XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace, Encoding) |
初始化類別的新實例 |
| XmlParserContext(XmlNameTable, XmlNamespaceManager, String, String, String, String, String, String, XmlSpace) |
初始化一個新的類別實例 |
| XmlParserContext(XmlNameTable, XmlNamespaceManager, String, String, String, String, String, String, XmlSpace, Encoding) |
初始化類別的新實例 |
XmlParserContext(XmlNameTable, XmlNamespaceManager, String, XmlSpace)
初始化一個新的類別實例 XmlParserContext ,包含指定的 XmlNameTable、 XmlNamespaceManager、 xml:lang和 xml: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 準鏡。
例外狀況
nt並非用來構造 XmlNameTable的相同nsMgr方法。
範例
以下範例讀取一個 XML 片段。 它使用 an XmlParserContext 和 its 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)
初始化類別的新實例XmlParserContext,並以指定的 XmlNameTable、 XmlNamespaceManager、 xml:langxml: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 準鏡。
例外狀況
nt並非用來構造 XmlNameTable的相同nsMgr方法。
適用於
XmlParserContext(XmlNameTable, XmlNamespaceManager, String, String, String, String, String, String, XmlSpace)
初始化一個新的類別實例 XmlParserContext ,並以指定的 XmlNameTable、 XmlNamespaceManager、 基礎 URI、 xml:lang及 xml: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 準鏡。
例外狀況
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 資料傳遞給 XmlTextReader,所有 DTD 資訊將被忽略。
如果你以 的 方式傳遞 DTD,DTD internalSubset是用於實體解析,而非文件驗證。
適用於
XmlParserContext(XmlNameTable, XmlNamespaceManager, String, String, String, String, String, String, XmlSpace, Encoding)
初始化類別的新實例 XmlParserContext ,包含指定的 XmlNameTable、 XmlNamespaceManager、 基礎 URI、 xml:lang、 xml: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 準鏡。
例外狀況
nt並非用來構造 XmlNameTable的相同nsMgr方法。