XmlTextWriter.WriteEndAttribute メソッド
アセンブリ: System.Xml (system.xml.dll 内)


![]() |
---|
Microsoft .NET Framework version 2.0 リリースでは、System.Xml.XmlWriter.Create メソッドと XmlWriterSettings クラスを使用して XmlWriter インスタンスを作成することをお勧めします。これにより、このリリースで導入されたすべての新機能を十分に活用できます。詳細については、「XML ライタの作成」を参照してください。 |
WriteStartAttribute を呼び出すと、このメソッドで属性を閉じることができます。
WriteStartAttribute を再び呼び出すか、WriteAttributeStringまたは WriteEndElement を呼び出して、属性を閉じることもできます。

Option Strict Option Explicit Imports System Imports System.IO Imports System.Xml Public Class Sample Private Shared filename As String = "sampledata.xml" Public Shared Sub Main() Dim writer As New XmlTextWriter(filename, Nothing) 'Use indenting for readability. writer.Formatting = Formatting.Indented writer.WriteComment("sample XML fragment") 'Write an element (this one is the root). writer.WriteStartElement("bookstore") 'Write the namespace declaration. writer.WriteAttributeString("xmlns", "bk", Nothing, "urn:samples") writer.WriteStartElement("book") 'Lookup the prefix and then write the ISBN attribute. Dim prefix As String = writer.LookupPrefix("urn:samples") writer.WriteStartAttribute(prefix, "ISBN", "urn:samples") writer.WriteString("1-861003-78") writer.WriteEndAttribute() 'Write the title. writer.WriteStartElement("title") writer.WriteString("The Handmaid's Tale") writer.WriteEndElement() 'Write the price. writer.WriteElementString("price", "19.95") 'Write the style element. writer.WriteStartElement(prefix, "style", "urn:samples") writer.WriteString("hardcover") writer.WriteEndElement() 'Write the end tag for the book element. writer.WriteEndElement() 'Write the close tag for the root element. writer.WriteEndElement() 'Write the XML to file and close the writer. writer.Flush() writer.Close() 'Read the file back in and parse to ensure well formed XML. Dim doc As New XmlDocument() 'Preserve white space for readability. doc.PreserveWhitespace = True 'Load the file. doc.Load(filename) 'Write the XML content to the console. Console.Write(doc.InnerXml) End Sub 'Main End Class 'Sample
using System; using System.IO; using System.Xml; public class Sample { private const string filename = "sampledata.xml"; public static void Main() { XmlTextWriter writer = new XmlTextWriter (filename, null); //Use indenting for readability. writer.Formatting = Formatting.Indented; writer.WriteComment("sample XML fragment"); //Write an element (this one is the root). writer.WriteStartElement("bookstore"); //Write the namespace declaration. writer.WriteAttributeString("xmlns", "bk", null, "urn:samples"); writer.WriteStartElement("book"); //Lookup the prefix and then write the ISBN attribute. string prefix = writer.LookupPrefix("urn:samples"); writer.WriteStartAttribute(prefix, "ISBN", "urn:samples"); writer.WriteString("1-861003-78"); writer.WriteEndAttribute(); //Write the title. writer.WriteStartElement("title"); writer.WriteString("The Handmaid's Tale"); writer.WriteEndElement(); //Write the price. writer.WriteElementString("price", "19.95"); //Write the style element. writer.WriteStartElement(prefix, "style", "urn:samples"); writer.WriteString("hardcover"); writer.WriteEndElement(); //Write the end tag for the book element. writer.WriteEndElement(); //Write the close tag for the root element. writer.WriteEndElement(); //Write the XML to file and close the writer. writer.Flush(); writer.Close(); //Read the file back in and parse to ensure well formed XML. XmlDocument doc = new XmlDocument(); //Preserve white space for readability. doc.PreserveWhitespace = true; //Load the file doc.Load(filename); //Write the XML content to the console. Console.Write(doc.InnerXml); } }
#using <System.Xml.dll> using namespace System; using namespace System::IO; using namespace System::Xml; int main() { String^ filename = "sampledata.xml"; XmlTextWriter^ writer = gcnew XmlTextWriter( filename, nullptr ); //Use indenting for readability. writer->Formatting = Formatting::Indented; writer->WriteComment( "sample XML fragment" ); //Write an element (this one is the root). writer->WriteStartElement( "bookstore" ); //Write the namespace declaration. writer->WriteAttributeString( "xmlns", "bk", nullptr, "urn:samples" ); writer->WriteStartElement( "book" ); //Lookup the prefix and then write the ISBN attribute. String^ prefix = writer->LookupPrefix( "urn:samples" ); writer->WriteStartAttribute( prefix, "ISBN", "urn:samples" ); writer->WriteString( "1-861003-78" ); writer->WriteEndAttribute(); //Write the title. writer->WriteStartElement( "title" ); writer->WriteString( "The Handmaid's Tale" ); writer->WriteEndElement(); //Write the price. writer->WriteElementString( "price", "19.95" ); //Write the style element. writer->WriteStartElement( prefix, "style", "urn:samples" ); writer->WriteString( "hardcover" ); writer->WriteEndElement(); //Write the end tag for the book element. writer->WriteEndElement(); //Write the close tag for the root element. writer->WriteEndElement(); //Write the XML to file and close the writer. writer->Flush(); writer->Close(); //Read the file back in and parse to ensure well formed XML. XmlDocument^ doc = gcnew XmlDocument; //Preserve white space for readability. doc->PreserveWhitespace = true; //Load the file doc->Load( filename ); //Write the XML content to the console. Console::Write( doc->InnerXml ); }
import System.*; import System.IO.*; import System.Xml.*; public class Sample { private static String fileName = "sampledata.xml"; public static void main(String[] args) { XmlTextWriter writer = new XmlTextWriter(fileName, null); //Use indenting for readability. writer.set_Formatting(Formatting.Indented); writer.WriteComment("sample XML fragment"); //Write an element (this one is the root). writer.WriteStartElement("bookstore"); //Write the namespace declaration. writer.WriteAttributeString("xmlns","bk", null, "urn:samples"); writer.WriteStartElement("book"); //Lookup the prefix and then write the ISBN attribute. String prefix = writer.LookupPrefix("urn:samples"); writer.WriteStartAttribute(prefix, "ISBN", "urn:samples"); writer.WriteString("1-861003-78"); writer.WriteEndAttribute(); //Write the title. writer.WriteStartElement("title"); writer.WriteString("The Handmaid's Tale"); writer.WriteEndElement(); //Write the price. writer.WriteElementString("price", "19.95"); //Write the style element. writer.WriteStartElement(prefix, "style", "urn:samples"); writer.WriteString("hardcover"); writer.WriteEndElement(); //Write the end tag for the book element. writer.WriteEndElement(); //Write the close tag for the root element. writer.WriteEndElement(); //Write the XML to file and close the writer. writer.Flush(); writer.Close(); //Read the file back in and parse to ensure well formed XML. XmlDocument doc = new XmlDocument(); //Preserve white space for readability. doc.set_PreserveWhitespace(true); //Load the file doc.Load(fileName); //Write the XML content to the console. Console.Write(doc.get_InnerXml()); } //main } //Sample

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からXmlTextWriter.WriteEndAttribute メソッドを検索する場合は、下記のリンクをクリックしてください。

- XmlTextWriter.WriteEndAttribute メソッドのページへのリンク