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

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

XmlWriter.WriteNode メソッド (XmlReader, Boolean)

派生クラスオーバーライドされると、リーダーデータをすべてライタコピーしリーダー次の兄弟開始位置移動します

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

Public Overridable Sub WriteNode
 ( _
    reader As XmlReader, _
    defattr As Boolean _
)
Dim instance As XmlWriter
Dim reader As XmlReader
Dim defattr As Boolean

instance.WriteNode(reader, defattr)
public virtual void WriteNode (
    XmlReader reader,
    bool defattr
)
public:
virtual void WriteNode (
    XmlReader^ reader, 
    bool defattr
)
public void WriteNode (
    XmlReader reader, 
    boolean defattr
)
public function WriteNode (
    reader : XmlReader, 
    defattr : boolean
)

パラメータ

reader

読み取り元の XmlReader

defattr

XmlReader既定属性コピーする場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentNullException

readernull 参照 (Visual Basic では Nothing) です。

解説解説

このメソッドサポートされノード型を次の表に示します

リーダー初期状態場合、このメソッドリーダーファイル末尾移動しますリーダーが既にファイル末尾にあるか、終了状態の場合、このメソッド機能しません。

次の C# コードは、XML 入力ドキュメント全体コンソールコピーします

XmlReader reader = XmlReader.Create(myfile);
XmlWriter writer = XmlWriter.Create(Console.Out);
writer.WriteNode(reader, false);

ルート ノードから離れてドキュメント内の別の場所にいる場合次の C# の例は、ノード正しく書き込みます

XmlReader reader = XmlReader.Create(myfile);
reader.Read(); // Read PI
reader.Read(); // Read Comment
reader.Read(); // Read DOCType
XmlWriter writer = XmlWriter.Create(Console.Out);
while (!reader.EOF){
  writer.WriteNode(reader, false);
 }

リーダー空白返すように構成されライタ出力インデント設定するように構成されていると、WriteNode予期しない出力生成する場合あります基本的に二重の書式指定生成されます。

使用例使用例

最初最後Book ノードコンソール書き込む例を次に示します

Imports System
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()

    Dim reader as XmlTextReader = new
 XmlTextReader("books.xml")
    reader.WhitespaceHandling = WhitespaceHandling.None

    'Move the reader to the first book element.
    reader.MoveToContent()
    reader.Read()

    'Create a writer that outputs to the console.
    Dim writer as XmlTextWriter = new
 XmlTextWriter (Console.Out)
    writer.Formatting = Formatting.Indented
    
    'Write the start tag.
    writer.WriteStartElement("myBooks")

    'Write the first book.
    writer.WriteNode(reader, false)

    'Skip the second book.
    reader.Skip()

    'Write the last book.
    writer.WriteNode(reader, false)
    writer.WriteEndElement()

    'Close the writer and the reader.
    writer.Close()
    reader.Close()

  end sub
end class
using System;
using System.IO;
using System.Xml;

public class Sample{

  public static void Main(){

    XmlTextReader reader = new XmlTextReader("books.xml");
    reader.WhitespaceHandling = WhitespaceHandling.None;

    //Move the reader to the first book element.
    reader.MoveToContent();
    reader.Read();

    //Create a writer that outputs to the console.
    XmlTextWriter writer = new XmlTextWriter (Console.Out);
    writer.Formatting = Formatting.Indented;
    
    //Write the start tag.
    writer.WriteStartElement("myBooks");

    //Write the first book.
    writer.WriteNode(reader, false);

    //Skip the second book.
    reader.Skip();

    //Write the last book.
    writer.WriteNode(reader, false);
    writer.WriteEndElement();

    //Close the writer and the reader.
    writer.Close();
    reader.Close();

  }
}
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlTextReader^ reader = gcnew XmlTextReader( "books.xml" );
   reader->WhitespaceHandling = WhitespaceHandling::None;
   
   // Move the reader to the first book element.
   reader->MoveToContent();
   reader->Read();
   
   // Create a writer that outputs to the console.
   XmlTextWriter^ writer = gcnew XmlTextWriter( Console::Out );
   writer->Formatting = Formatting::Indented;
   
   // Write the start tag.
   writer->WriteStartElement( "myBooks" );
   
   // Write the first book.
   writer->WriteNode( reader, false );
   
   // Skip the second book.
   reader->Skip();
   
   // Write the last book.
   writer->WriteNode( reader, false );
   writer->WriteEndElement();
   
   // Close the writer and the reader.
   writer->Close();
   reader->Close();
}

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

public class Sample
{
    public static void main(String[]
 args)
    {
        XmlTextReader reader = new XmlTextReader("books.xml");
        reader.set_WhitespaceHandling(WhitespaceHandling.None);
        //Move the reader to the first book element.
        reader.MoveToContent();
        reader.Read();
        //Create a writer that outputs to the console.
        XmlTextWriter writer = new XmlTextWriter(Console.get_Out());
        writer.set_Formatting(Formatting.Indented);
        //Write the start tag.
        writer.WriteStartElement("myBooks");
        //Write the first book.
        writer.WriteNode(reader, false);
        //Skip the second book.
        reader.Skip();
        //Write the last book.
        writer.WriteNode(reader, false);
        writer.WriteEndElement();
        //Close the writer and the reader.
        writer.Close();
        reader.Close();
    } //main 
} //Sample

この例では、入力として、books.xml というファイル使用してます。

<bookstore>
  <book genre="autobiography"
 publicationdate="1981" ISBN="1-861003-11-0">
    <title>The Autobiography
 of Benjamin Franklin</title>
    <author>
      <first-name>Benjamin</first-name>
      <last-name>Franklin</last-name>
    </author>
    <price>8.99</price>
  </book>
  <book genre="novel" publicationdate="1967"
 ISBN="0-201-63361-2">
    <title>The Confidence
 Man</title>
    <author>
      <first-name>Herman</first-name>
      <last-name>Melville</last-name>
    </author>
    <price>11.99</price>
  </book>
  <book genre="philosophy" publicationdate="1991"
 ISBN="1-861001-57-6">
    <title>The Gorgias</title>
    <author>
      <name>Plato</name>
    </author>
    <price>9.99</price>
  </book>
</bookstore>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

XmlWriter.WriteNode メソッド

ソース オブジェクトから現在のライタインスタンスにすべてをコピーします
オーバーロードの一覧オーバーロードの一覧

名前 説明
XmlWriter.WriteNode (XmlReader, Boolean) 派生クラスオーバーライドされると、リーダーデータをすべてライタコピーしリーダー次の兄弟開始位置移動します

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

XmlWriter.WriteNode (XPathNavigator, Boolean) XPathNavigator オブジェクトからライタにすべてをコピーしますXPathNavigator位置変更されません。
参照参照

関連項目

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

その他の技術情報

XmlWriter による XML書き方
XmlWriter による XML書き方
XmlWriter による XML書き方

XmlWriter.WriteNode メソッド (XPathNavigator, Boolean)

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

XPathNavigator オブジェクトからライタにすべてをコピーしますXPathNavigator位置変更されません。

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

Public Overridable Sub WriteNode
 ( _
    navigator As XPathNavigator, _
    defattr As Boolean _
)
Dim instance As XmlWriter
Dim navigator As XPathNavigator
Dim defattr As Boolean

instance.WriteNode(navigator, defattr)
public virtual void WriteNode (
    XPathNavigator navigator,
    bool defattr
)
public:
virtual void WriteNode (
    XPathNavigator^ navigator, 
    bool defattr
)
public void WriteNode (
    XPathNavigator navigator, 
    boolean defattr
)
public function WriteNode (
    navigator : XPathNavigator, 
    defattr : boolean
)

パラメータ

navigator

コピー元の XPathNavigator。

defattr

既定属性コピーする場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentNullException

navigatornull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

カテゴリ一覧

すべての辞書の索引



Weblioのサービス

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

   

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



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

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

©2024 GRAS Group, Inc.RSS