XmlParserContextとは? わかりやすく解説

XmlParserContext クラス

XML フラグメントを解析するために XmlReader が必要とするコンテキスト情報をすべて提供します。

名前空間: System.Xml
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Public Class XmlParserContext
Dim instance As XmlParserContext
public class XmlParserContext
public ref class XmlParserContext
public class XmlParserContext
public class XmlParserContext
使用例使用例

XML フラグメントを読み取る XmlReader オブジェクトを作成する例を次に示します。

Dim xmlFrag As String =
 "<item rk:ID='abc-23'>hammer</item> " &
 _
                                     "<item rk:ID='r2-435'>paint</item>"
 & _
                                     "<item rk:ID='abc-39'>saw</item>"

' Create the XmlNamespaceManager.
Dim nt As New NameTable()
Dim nsmgr As New XmlNamespaceManager(nt)
nsmgr.AddNamespace("rk", "urn:store-items")

' Create the XmlParserContext.
Dim context As New XmlParserContext(Nothing,
 nsmgr, Nothing, XmlSpace.None)

' Create the reader. 
Dim settings As New XmlReaderSettings()
settings.ConformanceLevel = ConformanceLevel.Fragment
Dim reader As XmlReader = XmlReader.Create(New
 StringReader(xmlFrag), settings, context)
string xmlFrag ="<item rk:ID='abc-23'>hammer</item>
 " +
                        "<item rk:ID='r2-435'>paint</item>"
 +
                        "<item rk:ID='abc-39'>saw</item>";

// Create the XmlNamespaceManager.
NameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
nsmgr.AddNamespace("rk", "urn:store-items");

// Create the XmlParserContext.
XmlParserContext context = new XmlParserContext(null,
 nsmgr, null, XmlSpace.None);

// Create the reader. 
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Fragment;
XmlReader reader = XmlReader.Create(new StringReader(xmlFrag),
 settings, context);

継承階層継承階層
System.Object
  System.Xml.XmlParserContext
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

XmlParserContext コンストラクタ (XmlNameTable, XmlNamespaceManager, String, String, String, String, String, String, XmlSpace, Encoding)

XmlNameTable、XmlNamespaceManager、ベース URI、xml:lang、xml:space、エンコーディング、およびドキュメント型のそれぞれの値を指定して、XmlParserContext クラスの新しいインスタンスを初期化します。

名前空間: System.Xml
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

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 _
)
Dim nt As XmlNameTable
Dim nsMgr As XmlNamespaceManager
Dim docTypeName As String
Dim pubId As String
Dim sysId As String
Dim internalSubset As String
Dim baseURI As String
Dim xmlLang As String
Dim xmlSpace As XmlSpace
Dim enc As Encoding

Dim instance As New XmlParserContext(nt,
 nsMgr, docTypeName, pubId, sysId, internalSubset, baseURI, xmlLang, xmlSpace, enc)
public XmlParserContext (
    XmlNameTable nt,
    XmlNamespaceManager nsMgr,
    string docTypeName,
    string pubId,
    string sysId,
    string internalSubset,
    string baseURI,
    string xmlLang,
    XmlSpace xmlSpace,
    Encoding enc
)
public:
XmlParserContext (
    XmlNameTable^ nt, 
    XmlNamespaceManager^ nsMgr, 
    String^ docTypeName, 
    String^ pubId, 
    String^ sysId, 
    String^ internalSubset, 
    String^ baseURI, 
    String^ xmlLang, 
    XmlSpace xmlSpace, 
    Encoding^ enc
)
public XmlParserContext (
    XmlNameTable nt, 
    XmlNamespaceManager nsMgr, 
    String docTypeName, 
    String pubId, 
    String sysId, 
    String internalSubset, 
    String baseURI, 
    String xmlLang, 
    XmlSpace xmlSpace, 
    Encoding enc
)
public function XmlParserContext (
    nt : XmlNameTable, 
    nsMgr : XmlNamespaceManager, 
    docTypeName : String, 
    pubId : String, 
    sysId : String, 
    internalSubset : String, 
    baseURI : String, 
    xmlLang : String, 
    xmlSpace : XmlSpace, 
    enc : Encoding
)

パラメータ

nt

文字列を最小単位に分割するために使用する XmlNameTable。このパラメータが null 参照 (Visual Basic では Nothing) の場合は、nsMgr を構築するために使用される名前テーブルが代わりに使用されます。最小単位に分割された文字列の詳細については、XmlNameTable のトピックを参照してください。

nsMgr

名前空間情報を検索するために使用する XmlNamespaceManager。または null 参照 (Visual Basic では Nothing)。

docTypeName

ドキュメント型宣言の名前。

pubId

パブリック識別子。

sysId

システム識別子。

internalSubset

内部 DTD サブセット。

baseURI

XML フラグメントのベース URI (フラグメントの読み込み元の場所)。

xmlLang

xml:lang スコープ。

xmlSpace

xml:space スコープを示す XmlSpace 値。

enc

エンコーディングの設定を示す Encoding オブジェクト。

例外例外
例外の種類条件

XmlException

nt が、nsMgr を構築するために使用される XmlNameTable と異なります。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlParserContext クラス
XmlParserContext メンバ
System.Xml 名前空間

XmlParserContext コンストラクタ (XmlNameTable, XmlNamespaceManager, String, XmlSpace, Encoding)

XmlNameTable、XmlNamespaceManager、xml:lang,、xml:space、およびエンコーディングを指定して、XmlParserContext クラスの新しいインスタンスを初期化します。

名前空間: System.Xml
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Public Sub New ( _
    nt As XmlNameTable, _
    nsMgr As XmlNamespaceManager, _
    xmlLang As String, _
    xmlSpace As XmlSpace, _
    enc As Encoding _
)
Dim nt As XmlNameTable
Dim nsMgr As XmlNamespaceManager
Dim xmlLang As String
Dim xmlSpace As XmlSpace
Dim enc As Encoding

Dim instance As New XmlParserContext(nt,
 nsMgr, xmlLang, xmlSpace, enc)
public XmlParserContext (
    XmlNameTable nt,
    XmlNamespaceManager nsMgr,
    string xmlLang,
    XmlSpace xmlSpace,
    Encoding enc
)
public:
XmlParserContext (
    XmlNameTable^ nt, 
    XmlNamespaceManager^ nsMgr, 
    String^ xmlLang, 
    XmlSpace xmlSpace, 
    Encoding^ enc
)
public XmlParserContext (
    XmlNameTable nt, 
    XmlNamespaceManager nsMgr, 
    String xmlLang, 
    XmlSpace xmlSpace, 
    Encoding enc
)
public function XmlParserContext (
    nt : XmlNameTable, 
    nsMgr : XmlNamespaceManager, 
    xmlLang : String, 
    xmlSpace : XmlSpace, 
    enc : Encoding
)

パラメータ

nt

文字列を最小単位に分割するために使用する XmlNameTable。このパラメータが null 参照 (Visual Basic では Nothing) の場合は、nsMgr を構築するために使用される名前テーブルが代わりに使用されます。最小単位に分割された文字列の詳細については、XmlNameTable のトピックを参照してください。

nsMgr

名前空間情報を検索するために使用する XmlNamespaceManager。または null 参照 (Visual Basic では Nothing)。

xmlLang

xml:lang スコープ。

xmlSpace

xml:space スコープを示す XmlSpace 値。

enc

エンコーディングの設定を示す Encoding オブジェクト。

例外例外
例外の種類条件

XmlException

nt が、nsMgr を構築するために使用される XmlNameTable と異なります。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlParserContext クラス
XmlParserContext メンバ
System.Xml 名前空間

XmlParserContext コンストラクタ (XmlNameTable, XmlNamespaceManager, String, String, String, String, String, String, XmlSpace)

XmlNameTable、XmlNamespaceManager、ベース URI、xml:lang、xml:space、ドキュメント型のそれぞれの値を指定して、XmlParserContext クラスの新しいインスタンスを初期化します。

名前空間: System.Xml
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

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 _
)
Dim nt As XmlNameTable
Dim nsMgr As XmlNamespaceManager
Dim docTypeName As String
Dim pubId As String
Dim sysId As String
Dim internalSubset As String
Dim baseURI As String
Dim xmlLang As String
Dim xmlSpace As XmlSpace

Dim instance As New XmlParserContext(nt,
 nsMgr, docTypeName, pubId, sysId, internalSubset, baseURI, xmlLang, xmlSpace)
public XmlParserContext (
    XmlNameTable nt,
    XmlNamespaceManager nsMgr,
    string docTypeName,
    string pubId,
    string sysId,
    string internalSubset,
    string baseURI,
    string xmlLang,
    XmlSpace xmlSpace
)
public:
XmlParserContext (
    XmlNameTable^ nt, 
    XmlNamespaceManager^ nsMgr, 
    String^ docTypeName, 
    String^ pubId, 
    String^ sysId, 
    String^ internalSubset, 
    String^ baseURI, 
    String^ xmlLang, 
    XmlSpace xmlSpace
)
public XmlParserContext (
    XmlNameTable nt, 
    XmlNamespaceManager nsMgr, 
    String docTypeName, 
    String pubId, 
    String sysId, 
    String internalSubset, 
    String baseURI, 
    String xmlLang, 
    XmlSpace xmlSpace
)
public function XmlParserContext (
    nt : XmlNameTable, 
    nsMgr : XmlNamespaceManager, 
    docTypeName : String, 
    pubId : String, 
    sysId : String, 
    internalSubset : String, 
    baseURI : String, 
    xmlLang : String, 
    xmlSpace : XmlSpace
)

パラメータ

nt

文字列を最小単位に分割するために使用する XmlNameTable。このパラメータが null 参照 (Visual Basic では Nothing) の場合は、nsMgr を構築するために使用される名前テーブルが代わりに使用されます。最小単位に分割された文字列の詳細については、XmlNameTable のトピックを参照してください。

nsMgr

名前空間情報を検索するために使用する XmlNamespaceManager。または null 参照 (Visual Basic では Nothing)。

docTypeName

ドキュメント型宣言の名前。

pubId

パブリック識別子。

sysId

システム識別子。

internalSubset

内部 DTD サブセット。

baseURI

XML フラグメントのベース URI (フラグメントの読み込み元の場所)。

xmlLang

xml:lang スコープ。

xmlSpace

xml:space スコープを示す XmlSpace 値。

例外例外
例外の種類条件

XmlException

nt が、nsMgr を構築するために使用される XmlNameTable と異なります。

解説解説

このコンストラクタは、XmlValidatingReader が必要とする DocumentType 情報をすべて提供します。この XmlParserContext が XmlTextReader に渡されると、DTD 情報はすべて無視されます。

使用例使用例

XmlParserContext を使用して、XML フラグメントを読み取る例を次に示します。

Option Explicit On
Option Strict On

Imports System
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 'Main
End Class 'Sample
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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlParserContext クラス
XmlParserContext メンバ
System.Xml 名前空間

XmlParserContext コンストラクタ

値を指定して、XmlParserContext クラスの新しいインスタンスを初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
XmlParserContext (XmlNameTable, XmlNamespaceManager, String, XmlSpace) XmlNameTable、XmlNamespaceManager、xml:lang、および xml:space のそれぞれの値を指定して、XmlParserContext クラスの新しいインスタンスを初期化します。

.NET Compact Framework によってサポートされています。

XmlParserContext (XmlNameTable, XmlNamespaceManager, String, XmlSpace, Encoding) XmlNameTable、XmlNamespaceManager、xml:lang,、xml:space、およびエンコーディングを指定して、XmlParserContext クラスの新しいインスタンスを初期化します。

.NET Compact Framework によってサポートされています。

XmlParserContext (XmlNameTable, XmlNamespaceManager, String, String, String, String, String, String, XmlSpace) XmlNameTable、XmlNamespaceManager、ベース URI、xml:lang、xml:space、ドキュメント型のそれぞれの値を指定して、XmlParserContext クラスの新しいインスタンスを初期化します。

.NET Compact Framework によってサポートされています。

XmlParserContext (XmlNameTable, XmlNamespaceManager, String, String, String, String, String, String, XmlSpace, Encoding) XmlNameTable、XmlNamespaceManager、ベース URI、xml:lang、xml:space、エンコーディング、およびドキュメント型のそれぞれの値を指定して、XmlParserContext クラスの新しいインスタンスを初期化します。

.NET Compact Framework によってサポートされています。

参照参照

関連項目

XmlParserContext クラス
XmlParserContext メンバ
System.Xml 名前空間

XmlParserContext コンストラクタ (XmlNameTable, XmlNamespaceManager, String, XmlSpace)

XmlNameTable、XmlNamespaceManager、xml:lang、および xml:space のそれぞれの値を指定して、XmlParserContext クラスの新しいインスタンスを初期化します。

名前空間: System.Xml
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Public Sub New ( _
    nt As XmlNameTable, _
    nsMgr As XmlNamespaceManager, _
    xmlLang As String, _
    xmlSpace As XmlSpace _
)
Dim nt As XmlNameTable
Dim nsMgr As XmlNamespaceManager
Dim xmlLang As String
Dim xmlSpace As XmlSpace

Dim instance As New XmlParserContext(nt,
 nsMgr, xmlLang, xmlSpace)
public XmlParserContext (
    XmlNameTable nt,
    XmlNamespaceManager nsMgr,
    string xmlLang,
    XmlSpace xmlSpace
)
public:
XmlParserContext (
    XmlNameTable^ nt, 
    XmlNamespaceManager^ nsMgr, 
    String^ xmlLang, 
    XmlSpace xmlSpace
)
public XmlParserContext (
    XmlNameTable nt, 
    XmlNamespaceManager nsMgr, 
    String xmlLang, 
    XmlSpace xmlSpace
)
public function XmlParserContext (
    nt : XmlNameTable, 
    nsMgr : XmlNamespaceManager, 
    xmlLang : String, 
    xmlSpace : XmlSpace
)

パラメータ

nt

文字列を最小単位に分割するために使用する XmlNameTable。このパラメータが null 参照 (Visual Basic では Nothing) の場合は、nsMgr を構築するために使用される名前テーブルが代わりに使用されます。最小単位に分割された文字列の詳細については、XmlNameTable のトピックを参照してください。

nsMgr

名前空間情報を検索するために使用する XmlNamespaceManager。または null 参照 (Visual Basic では Nothing)。

xmlLang

xml:lang スコープ。

xmlSpace

xml:space スコープを示す XmlSpace 値。

例外例外
例外の種類条件

XmlException

nt が、nsMgr を構築するために使用される XmlNameTable と異なります。

使用例使用例

XML フラグメントを読み取る例を次に示します。XmlParserContext とその XmlNamespaceManager を使用して、一致する名前空間を処理します。

Imports System
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 'Main
End Class 'Sample 
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 (reader.Prefix == String.Empty)
                        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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlParserContext クラス
XmlParserContext メンバ
System.Xml 名前空間

XmlParserContext プロパティ


XmlParserContext メソッド


XmlParserContext メンバ

XML フラグメントを解析するために XmlReader が必要とするコンテキスト情報をすべて提供します。

XmlParserContext データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ XmlSpace 現在の xml:space スコープを取得または設定します。
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

XmlParserContext クラス
System.Xml 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「XmlParserContext」の関連用語

XmlParserContextのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XmlParserContextのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS