XmlWriter.WriteNode メソッド (XmlReader, Boolean)
アセンブリ: System.Xml (system.xml.dll 内)

Dim instance As XmlWriter Dim reader As XmlReader Dim defattr As Boolean instance.WriteNode(reader, defattr)


ノード型 | WriteNode の動作 |
---|---|
None | 型に関係なく、すべてのノードを書き込みます。つまり、ライタは、属性、処理命令、コメントなどを含め、XmlReader を使用して読み取ったすべてのノードを書き込みます。 この状況は、XmlReader が初期状態にあると発生します (XmlReader.ReadState プロパティが ReaderState.Initial を返すとき)。 |
操作なし。代わりに、WriteStartAttribute または WriteAttributeString を使用します。 | |
CDATA | |
EntityReference | |
ProcessingInstruction | |
DocumentType | |
SignificantWhitespace | |
EndElement | |
EndEntity | 操作なし。 |
XmlDeclaration |
リーダーが初期状態の場合、このメソッドはリーダーをファイルの末尾に移動します。リーダーが既にファイルの末尾にあるか、終了状態の場合、このメソッドは機能しません。
次の 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>

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


XmlWriter.WriteNode メソッド

名前 | 説明 |
---|---|
XmlWriter.WriteNode (XmlReader, Boolean) | 派生クラスでオーバーライドされると、リーダーのデータをすべてライタにコピーし、リーダーを次の兄弟の開始位置に移動します。 .NET Compact Framework によってサポートされています。 |
XmlWriter.WriteNode (XPathNavigator, Boolean) | XPathNavigator オブジェクトからライタにすべてをコピーします。XPathNavigator の位置は変更されません。 |

XmlWriter.WriteNode メソッド (XPathNavigator, Boolean)
アセンブリ: System.Xml (system.xml.dll 内)

Dim instance As XmlWriter Dim navigator As XPathNavigator Dim defattr As Boolean instance.WriteNode(navigator, defattr)


このメソッドでサポートされる XPath ノード型を次の表に示します。
XPathNodeType | WriteNode の動作 |
---|---|
型に関係なく、すべてのノードを書き込みます。つまり、ライタは XPathNavigator を使用して、ルート ノードからすべてのノードを書き込みます (属性、処理命令、コメントなど)。 | |
操作なし。代わりに、WriteStartAttribute または WriteAttributeString を使用します。 | |
操作なし。名前空間宣言を書き込むには、WriteStartAttribute メソッドまたは WriteAttributeString メソッドを使用します。 | |
ProcessingInstruction | |
SignificantWhitespace | |


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

