Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

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

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

XmlDocument.CreateEntityReference メソッド

指定した名前を使用して、XmlEntityReference を作成します

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

Public Overridable Function
 CreateEntityReference ( _
    name As String _
) As XmlEntityReference
Dim instance As XmlDocument
Dim name As String
Dim returnValue As XmlEntityReference

returnValue = instance.CreateEntityReference(name)
public virtual XmlEntityReference CreateEntityReference (
    string name
)
public:
virtual XmlEntityReference^ CreateEntityReference (
    String^ name
)
public XmlEntityReference CreateEntityReference (
    String name
)
public function CreateEntityReference (
    name : String
) : XmlEntityReference

パラメータ

name

エンティティ参照の名前。

戻り値
新しXmlEntityReference

例外例外
例外種類条件

ArgumentException

名前が無効です。たとえば、'#' で始まる名前は無効です。

解説解説

参照されエンティティ既知の場合は、XmlEntityReference ノードの子リストは、対応する XmlEntity ノードの子リスト同じになります

エンティティ参照置換テキスト使用されている名前空間は、エンティティ参照ノードドキュメント挿入されたときなど、エンティティ参照ノードの親が最初に設定され時点バインドされます。たとえば、次のエンティティ指定した場合

<!ENTITY a "<b>test</b>">

CreateEntityReference("a")呼び出すと、子のない EntityReference 型の単一ノード返されます。このノード次のノードの子として追加する場合は、

<item xmlns="urn:1"/>

AppendChild を呼び出す時点で、新しく作成されエンティティ参照ノードの親が設定され、子はこの名前空間コンテキスト展開されます。子要素ノード b の NamespaceURI は、urn:1等しくなります既定名前空間コンテキスト異なドキュメント内の場所にエンティティ参照移動しても、エンティティ参照の子ノードは同じままです。既存エンティティ参照ノード削除および挿入する場合、または CloneNode を使用してクローン作成するエンティティ参照場合は、子ノード同じにはなりません。エンティティ参照の子ノードが同じままになるのは、新しく作成したエンティティ参照場合だけです。

エンティティ参照ノード追加したときに、対応するエンティティが DocumentType で定義されない場合は、エンティティ参照定義されていないため、唯一の子ノードは空のテキスト ノードなります

組み込みエンティティampltgtaposquot使用できます。これらのエンティティには、展開され適切な文字値を持つ子テキスト ノードあります

このメソッドは、ドキュメントコンテキスト内で新しオブジェクト作成しますが、自動的に新しオブジェクトドキュメント ツリー追加しません。新しオブジェクト追加するには、ノード挿入メソッドいずれか 1 つ明示的に呼び出す必要があります

W3C 勧告Extensible Markup Language (XML) 1.0』(www.w3.org/TR/1998/REC-xml-19980210) に従って、EntityReference ノードは、ElementAttribute、EntityReference の各ノード内だけで使用できます

使用例使用例

2 つエンティティ参照ノード作成しXML ドキュメント挿入する例を次に示します

Option Explicit
Option Strict

Imports System
Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        'Create the XmlDocument.
        Dim doc As New XmlDocument()
        doc.LoadXml("<!DOCTYPE book [<!ENTITY h 'hardcover'>]>"
 & _
                    "<book genre='novel' ISBN='1-861001-57-5'>"
  & _
                    "<title>Pride And Prejudice</title>"
  & _
                    "<misc/>"  & _
                    "</book>")
        
        'Create an entity reference node. The child count should be
 0 
        'since the node has not been expanded.
        Dim entityref As XmlEntityReference
 = doc.CreateEntityReference("h")
        Console.WriteLine(entityref.ChildNodes.Count)
        
        'After the the node has been added to the document, its parent
 node
        'is set and the entity reference node is expanded.  It now has
 a child
        'node containing the entity replacement text. 
        doc.DocumentElement.LastChild.AppendChild(entityref)
        Console.WriteLine(entityref.FirstChild.InnerText)
        
        'Create and insert an undefined entity reference node.  When
 the entity
        'reference node is expanded, because the entity reference is
 undefined
        'the child is an empty text node.
        Dim entityref2 As XmlEntityReference
 = doc.CreateEntityReference("p")
        doc.DocumentElement.LastChild.AppendChild(entityref2)
        Console.WriteLine(entityref2.FirstChild.InnerText)
    End Sub 'Main 
End Class 'Sample
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    //Create the XmlDocument.
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<!DOCTYPE book [<!ENTITY h 'hardcover'>]>"
 +
                "<book genre='novel' ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "<misc/>" +
                "</book>"); 

    //Create an entity reference node. The child count should be 0 
    //since the node has not been expanded.
    XmlEntityReference entityref = doc.CreateEntityReference("h");
    Console.WriteLine(entityref.ChildNodes.Count ); 

    //After the the node has been added to the document, its parent
 node
    //is set and the entity reference node is expanded.  It now has
 a child
    //node containing the entity replacement text. 
    doc.DocumentElement.LastChild.AppendChild(entityref);
    Console.WriteLine(entityref.FirstChild.InnerText);

    //Create and insert an undefined entity reference node.  When the
 entity
    //reference node is expanded, because the entity reference is undefined
    //the child is an empty text node.
    XmlEntityReference entityref2 = doc.CreateEntityReference("p");
    doc.DocumentElement.LastChild.AppendChild(entityref2);
    Console.WriteLine(entityref2.FirstChild.InnerText);
    
  }
}
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create the XmlDocument.
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<!DOCTYPE book [<!ENTITY h 'hardcover'>]><book
 genre='novel' ISBN='1-861001-57-5'><title>Pride And Prejudice</title><misc/></book>"
 );
   
   //Create an entity reference node. The child count should be 0 
   //since the node has not been expanded.
   XmlEntityReference^ entityref = doc->CreateEntityReference( "h" );
   Console::WriteLine( entityref->ChildNodes->Count );
   
   //After the the node has been added to the document, its parent node
   //is set and the entity reference node is expanded.  It now has a
 child
   //node containing the entity replacement text. 
   doc->DocumentElement->LastChild->AppendChild( entityref );
   Console::WriteLine( entityref->FirstChild->InnerText );
   
   //Create and insert an undefined entity reference node.  When the
 entity
   //reference node is expanded, because the entity reference is undefined
   //the child is an empty text node.
   XmlEntityReference^ entityref2 = doc->CreateEntityReference( "p"
 );
   doc->DocumentElement->LastChild->AppendChild( entityref2 );
   Console::WriteLine( entityref2->FirstChild->InnerText );
}

import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[]
 args)
    {
        //Create the XmlDocument.
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<!DOCTYPE book [<!ENTITY h 'hardcover'>]>"
                    + "<book genre='novel' ISBN='1-861001-57-5'>"
                    + "<title>Pride And Prejudice</title>"
                    + "<misc/>"
                    + "</book>");

        //Create an entity reference node. The child count should be
 0 
        //since the node has not been expanded.
        XmlEntityReference entityRef = doc.CreateEntityReference("h");
        Console.WriteLine(entityRef.get_ChildNodes().get_Count());

        //After the the node has been added to the document, its parent
 node
        //is set and the entity reference node is expanded.  It now has
 a child
        //node containing the entity replacement text. 
        doc.get_DocumentElement().get_LastChild().AppendChild(entityRef);
        Console.WriteLine(entityRef.get_FirstChild().get_InnerText());

        //Create and insert an undefined entity reference node.  When the
 entity
        //reference node is expanded, because the entity reference is
 undefined
        //the child is an empty text node.
        XmlEntityReference entityRef2 = doc.CreateEntityReference("p");
        doc.get_DocumentElement().get_LastChild().AppendChild(entityRef2);
        Console.WriteLine(entityRef2.get_FirstChild().get_InnerText());
    } //main
} //Sample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「XmlDocument.CreateEntityReference メソッド」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS