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

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

XmlDocument.LoadXml メソッド

指定した文字列から XML ドキュメントを読み込みます。

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

例外例外
例外の種類条件

XmlException

XML 内に読み込みエラーまたは解析エラーがあります。この場合、ドキュメントは空のままです。

解説解説

既定では、LoadXml メソッドは空白も有意な空白も保存しません。

このメソッドは、DTD 検証またはスキーマ検証を実行しません。検証を実行する場合は、Load メソッドを使用し、そのメソッドに XmlValidatingReader を渡します。読み込み時検証の例については、「XmlDocument」を参照してください。

このメソッドは、DOM (Document Object Model) に対する Microsoft 拡張機能です。

使用例使用例

XML を XmlDocument オブジェクトに読み込み、ファイルに保存する例を次に示します。

Imports System
Imports System.Xml

public class Sample 

  public shared sub Main()
 
 
    ' Create the XmlDocument.
    Dim doc as XmlDocument = new
 XmlDocument()
    doc.LoadXml("<item><name>wrench</name></item>")

   ' Add a price element.
   Dim newElem as XmlElement = doc.CreateElement("price")
   newElem.InnerText = "10.95"
   doc.DocumentElement.AppendChild(newElem)

    ' Save the document to a file and auto-indent the output.
    Dim writer as XmlTextWriter = new
 XmlTextWriter("data.xml",nothing)
    writer.Formatting = Formatting.Indented
    doc.Save(writer)
  end sub
end class
using System;
using System.Xml;

public class Sample {

  public static void Main()
 {
 
    // Create the XmlDocument.
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<item><name>wrench</name></item>");

   // Add a price element.
   XmlElement newElem = doc.CreateElement("price");
   newElem.InnerText = "10.95";
   doc.DocumentElement.AppendChild(newElem);

    // Save the document to a file and auto-indent the output.
    XmlTextWriter writer = new XmlTextWriter("data.xml"
,null);
    writer.Formatting = Formatting.Indented;
    doc.Save(writer);
  }
}
#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
int main()
{
   
   // Create the XmlDocument.
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<item><name>wrench</name></item>"
 );
   
   // Add a price element.
   XmlElement^ newElem = doc->CreateElement( "price" );
   newElem->InnerText = "10.95";
   doc->DocumentElement->AppendChild( newElem );
   
   // Save the document to a file and auto-indent the output.
   XmlTextWriter^ writer = gcnew XmlTextWriter( "data.xml", nullptr );
   writer->Formatting = Formatting::Indented;
   doc->Save( writer );
}

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

public class Sample
{
    public static void main(String[]
 args)
    {
        // Create the XmlDocument.
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<item><name>wrench</name></item>");

        // Add a price element.
        XmlElement newElem = doc.CreateElement("price");
        newElem.set_InnerText("10.95");
        doc.get_DocumentElement().AppendChild(newElem);

        // Save the document to a file and auto-indent the output.
        XmlTextWriter writer = new XmlTextWriter("data.xml",
 null);
        writer.set_Formatting(Formatting.Indented);
        doc.Save(writer);
    } //main
} //Sample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlDocument クラス
XmlDocument メンバ
System.Xml 名前空間
PreserveWhitespace



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2026 GRAS Group, Inc.RSS