XmlNamespaceManager.AddNamespace メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlNamespaceManager.AddNamespace メソッドの意味・解説 

XmlNamespaceManager.AddNamespace メソッド

指定した名前空間コレクション追加します

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

例外例外
例外種類条件

ArgumentException

prefix の値が "xml" または "xmlns" です。

ArgumentNullException

prefix または uri の値が null 参照 (Visual Basic では Nothing) です。

解説解説

XmlNamespaceManager は、prefix および uri準拠性をチェックしません。

XmlReader は、プレフィックスおよび名前空間含めて名前をチェックしW3C (World Wide Web Consortium) の仕様に従う有効な XML 名であることを確認しますXmlNamespaceManagerXmlReader によって内部的に使用されるため、処理の重複避けるために、XmlNamespaceManagerすべてのプレフィックスおよび名前空間を有効と見なします。

プレフィックス名前空間が既に現在のスコープ内に存在している場合は、新しプレフィックス名前空間ペアが既存プレフィックス名前空間組み合わせ置き換えます異なスコープ間で同じプリフィックス名前空間組み合わせ存在してかまいません

既定では、次のプリフィクス名前空間ペアが XmlNamespaceManager追加されます。これらの組み合わせはどのスコープでも確認できます

プリフィックス

名前空間

xmlns

http://www.w3.org/2000/xmlns/ (xmlns プリフィックス名前空間)

xml

http://www.w3.org/XML/1998/namespace (XML 名前空間)

String.Empty

String.Empty (空の名前空間)。この値には、異なプリフィックスを再割り当てできます。たとえば、xmlns="" は、既定名前空間を空の名前空間として定義します

使用例使用例

XmlNamespaceManager使用してXML フラグメント名前空間解決する例を次に示します

Imports System
Imports System.Xml

Public Class Sample

    Public Shared Sub Main()

        Dim reader As XmlTextReader = Nothing

        Try

            ' Create the string containing the XML to read.
            Dim xmlFrag As String
            xmlFrag = "<book>" & _
                           "<title>Pride And Prejudice</title>"
 & _
                           "<author>" &
 _
                           "<first-name>Jane</first-name>"
 & _
                           "<last-name>Austen</last-name>"
 & _
                           "</author>" &
 _
                           "<curr:price>19.95</curr:price>"
 & _
                           "<misc>&h;</misc>"
 & _
                           "</book>"

            ' Create an XmlNamespaceManager to resolve namespaces.
            Dim nt As NameTable = New
 NameTable()
            Dim nsmgr As XmlNamespaceManager
 = New XmlNamespaceManager(nt)
            nsmgr.AddNamespace(String.Empty, "urn:samples")
 'default namespace
            nsmgr.AddNamespace("curr", "urn:samples:dollar")

            ' Create an XmlParserContext.  The XmlParserContext contains
 all the information
            ' required to parse the XML fragment, including the entity
 information and the
            ' XmlNamespaceManager to use for namespace resolution.
            Dim context As XmlParserContext
            Dim subset As String
 = "<!ENTITY h 'hardcover'>"
            context = New XmlParserContext(nt, nsmgr, "book",
 Nothing, Nothing, subset, Nothing,
 Nothing, XmlSpace.None)

            ' Create the reader.
            reader = New XmlTextReader(xmlFrag, XmlNodeType.Element,
 context)

            ' Parse the file and display the node values.
            While (reader.Read())
                If (reader.HasValue) Then
                    Console.WriteLine("{0} [{1}] = {2}",
 reader.NodeType, reader.Name, reader.Value)
                Else
                    Console.WriteLine("{0} [{1}]",
 reader.NodeType, reader.Name)
                End If
            End While

        Finally
            If Not (reader Is
 Nothing) Then
                reader.Close()
            End If
        End Try
    End Sub
End Class
using System;
using System.Xml;

public class Sample
{

    public static void Main()
    {

        XmlTextReader reader = null;

        try
        {

            // Create the string containing the XML to read.
            String xmlFrag = "<book>" +
                           "<title>Pride And Prejudice</title>"
 +
                           "<author>" +
                           "<first-name>Jane</first-name>"
 +
                           "<last-name>Austen</last-name>"
 +
                           "</author>" +
                           "<curr:price>19.95</curr:price>"
 +
                           "<misc>&h;</misc>" +
                           "</book>";

            // Create an XmlNamespaceManager to resolve namespaces.
            NameTable nt = new NameTable();
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
            nsmgr.AddNamespace(String.Empty, "urn:samples"); //default
 namespace
            nsmgr.AddNamespace("curr", "urn:samples:dollar");

            // Create an XmlParserContext.  The XmlParserContext contains
 all the information
            // required to parse the XML fragment, including the entity
 information and the
            // XmlNamespaceManager to use for namespace resolution.
            XmlParserContext context;
            String subset = "<!ENTITY h 'hardcover'>";
            context = new XmlParserContext(nt, nsmgr, "book",
 null, null, subset, null,
 null, XmlSpace.None);

            // Create the reader.
            reader = new XmlTextReader(xmlFrag, XmlNodeType.Element,
 context);

            // Parse the file and display the node values.
            while (reader.Read())
            {
                if (reader.HasValue)
                    Console.WriteLine("{0} [{1}] = {2}", reader.NodeType,
 reader.Name, reader.Value);
                else
                    Console.WriteLine("{0} [{1}]", reader.NodeType, reader.Name);
            }
        }
        finally
        {
            if (reader != null)
                reader.Close();
        }
    }
} // End class
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlNamespaceManager クラス
XmlNamespaceManager メンバ
System.Xml 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からXmlNamespaceManager.AddNamespace メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からXmlNamespaceManager.AddNamespace メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からXmlNamespaceManager.AddNamespace メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

XmlNamespaceManager.AddNamespace メソッドのお隣キーワード
検索ランキング

   

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



XmlNamespaceManager.AddNamespace メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS