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

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

XmlDocument.CreateDocumentType メソッド

新しい XmlDocumentType オブジェクトを返します。

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

Public Overridable Function
 CreateDocumentType ( _
    name As String, _
    publicId As String, _
    systemId As String, _
    internalSubset As String _
) As XmlDocumentType
Dim instance As XmlDocument
Dim name As String
Dim publicId As String
Dim systemId As String
Dim internalSubset As String
Dim returnValue As XmlDocumentType

returnValue = instance.CreateDocumentType(name, publicId, systemId, internalSubset)
public virtual XmlDocumentType CreateDocumentType (
    string name,
    string publicId,
    string systemId,
    string internalSubset
)
public:
virtual XmlDocumentType^ CreateDocumentType (
    String^ name, 
    String^ publicId, 
    String^ systemId, 
    String^ internalSubset
)
public XmlDocumentType CreateDocumentType (
    String name, 
    String publicId, 
    String systemId, 
    String internalSubset
)
public function CreateDocumentType (
    name : String, 
    publicId : String, 
    systemId : String, 
    internalSubset : String
) : XmlDocumentType

パラメータ

name

ドキュメントの種類の名前。

publicId

ドキュメントの種類のパブリック ID。null 参照 (Visual Basic では Nothing)。パブリック URI およびシステム ID を指定して、外部 DTD サブセットの場所を特定できます。

systemId

ドキュメントの種類のシステム ID。または null 参照 (Visual Basic では Nothing)。外部 DTD サブセットのファイル位置の URL を指定します。

internalSubset

ドキュメントの種類の DTD 内部サブセット。または null 参照 (Visual Basic では Nothing)。

戻り値
新しい XmlDocumentType。

解説解説

返されたノードには、解析済みの Entities コレクションおよび Notations コレクションがあります。

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

W3C 勧告『Extensible Markup Language (XML) 1.0』(www.w3.org/TR/1998/REC-xml-19980210) に従って、DocumentType ノードは Document ノード内だけで使用できます。それぞれの XmlDocument は、DocumentType ノードを 1 つだけ持つことができます。DocumentType ノードも XmlDocument のルート要素より前に挿入する必要があります。つまり、ドキュメントに既にルート要素がある場合は、DocumentType ノードを追加できません。

渡されたパラメータを組み合わせても有効な XmlDocumentType が作成されない場合は、例外がスローされます。

継承時の注意 このメソッドには継承確認要求があります。CreateDocumentType メソッドをオーバーライドするには、完全な信頼が必要です。詳細については、「継承確認要求」を参照してください。 このメソッドは、DOM (Document Object Model) に対する Microsoft 拡張機能です。

使用例使用例

DocumentType ノードを作成し、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()
        
        'Create a document type node and  
        'add it to the document.
        Dim doctype As XmlDocumentType
        doctype = doc.CreateDocumentType("book", Nothing,
 Nothing, "<!ELEMENT book ANY>")
        doc.AppendChild(doctype)
        
        'Create the root element and 
        'add it to the document.
        doc.AppendChild(doc.CreateElement("book"))
        
        Console.WriteLine("Display the modified XML...")
        doc.Save(Console.Out)
    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();

    //Create a document type node and  
    //add it to the document.
    XmlDocumentType doctype;
    doctype = doc.CreateDocumentType("book", null, null,
 "<!ELEMENT book ANY>");
    doc.AppendChild(doctype);

    //Create the root element and 
    //add it to the document.
    doc.AppendChild(doc.CreateElement("book"));

    Console.WriteLine("Display the modified XML...");
    doc.Save(Console.Out);
  }
}
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create the XmlDocument.
   XmlDocument^ doc = gcnew XmlDocument;
   
   //Create a document type node and  
   //add it to the document.
   XmlDocumentType^ doctype;
   doctype = doc->CreateDocumentType( "book", nullptr, nullptr, "<!ELEMENT
 book ANY>" );
   doc->AppendChild( doctype );
   
   //Create the root element and 
   //add it to the document.
   doc->AppendChild( doc->CreateElement( "book" ) );
   Console::WriteLine( "Display the modified XML..." );
   doc->Save( Console::Out );
}

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

public class Sample
{
    public static void main(String[]
 args)
    {
        //Create the XmlDocument.
        XmlDocument doc = new XmlDocument();

        //Create a document type node and  
        //add it to the document.
        XmlDocumentType doctype;
        doctype = doc.CreateDocumentType("book", null,
 
            null, "<!ELEMENT book ANY>");
        doc.AppendChild(doctype);

        //Create the root element and 
        //add it to the document.
        doc.AppendChild(doc.CreateElement("book"));

        Console.WriteLine("Display the modified XML...");
        doc.Save(Console.get_Out());
    } //main
} //Sample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

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

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

   

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



XmlDocument.CreateDocumentType メソッドのページの著作権

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

©2026 GRAS Group, Inc.RSS