XmlWriter.WriteAttributeString メソッド
派生クラスでオーバーライドされると、指定した値の属性を書き込みます。
オーバーロードの一覧
派生クラスでオーバーライドされると、指定したローカル名と値の属性を書き込みます。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Sub WriteAttributeString(String, String)
[JScript] public function WriteAttributeString(String, String);
派生クラスでオーバーライドされると、指定したローカル名、名前空間 URI、および値の属性を書き込みます。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Sub WriteAttributeString(String, String, String)
[C#] public void WriteAttributeString(string, string, string);
[C++] public: void WriteAttributeString(String*, String*, String*);
[JScript] public function WriteAttributeString(String, String, String);
派生クラスでオーバーライドされると、指定したプリフィックス、ローカル名、名前空間 URI、および値の属性を書き込みます。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Sub WriteAttributeString(String, String, String, String)
[C#] public void WriteAttributeString(string, string, string, string);
[C++] public: void WriteAttributeString(String*, String*, String*, String*);
[JScript] public function WriteAttributeString(String, String, String, String);
使用例
[Visual Basic, C#, C++] XML スキーマ定義言語 (XSD) スキーマの一部を書き込む例を次に示します。
[Visual Basic, C#, C++] メモ ここでは、WriteAttributeString のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
Option Explicit
Option Strict
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 XmlTextWriter = Nothing
writer = New XmlTextWriter(filename, Nothing)
' Use indenting for readability.
writer.Formatting = Formatting.Indented
' Write the root element.
writer.WriteStartElement("schema")
' Write the namespace declarations.
writer.WriteAttributeString("xmlns", Nothing, "http://www.w3.org/2001/XMLSchema")
writer.WriteAttributeString("xmlns", "po", Nothing, "https://contoso.com/po")
writer.WriteStartElement("element")
writer.WriteAttributeString("name", "purchaseOrder")
' Write the type attribute.
writer.WriteStartAttribute(Nothing, "type", Nothing)
writer.WriteQualifiedName("PurchaseOrder", "https://contoso.com/po")
writer.WriteEndAttribute()
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
[C#]
using System;
using System.IO;
using System.Xml;
public class Sample
{
private const string filename = "sampledata.xml";
public static void Main()
{
XmlTextWriter writer = null;
writer = new XmlTextWriter (filename, null);
// Use indenting for readability.
writer.Formatting = Formatting.Indented;
// Write the root element.
writer.WriteStartElement("schema");
// Write the namespace declarations.
writer.WriteAttributeString("xmlns", null,"http://www.w3.org/2001/XMLSchema");
writer.WriteAttributeString("xmlns","po",null,"https://contoso.com/po");
writer.WriteStartElement("element");
writer.WriteAttributeString("name", "purchaseOrder");
// Write the type attribute.
writer.WriteStartAttribute(null,"type", null);
writer.WriteQualifiedName("PurchaseOrder", "https://contoso.com/po");
writer.WriteEndAttribute();
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);
}
}
[C++]
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
XmlTextWriter* writer = 0;
String* filename = S"sampledata.xml";
writer = new XmlTextWriter (filename, 0);
// Use indenting for readability.
writer->Formatting = Formatting::Indented;
// Write the root element.
writer->WriteStartElement(S"schema");
// Write the namespace declarations.
writer->WriteAttributeString(S"xmlns", 0,S"http://www.w3.org/2001/XMLSchema");
writer->WriteAttributeString(S"xmlns",S"po",0,S"https://contoso.com/po");
writer->WriteStartElement(S"element");
writer->WriteAttributeString(S"name", S"purchaseOrder");
// Write the type attribute.
writer->WriteStartAttribute(0,S"type", 0);
writer->WriteQualifiedName(S"PurchaseOrder", S"https://contoso.com/po");
writer->WriteEndAttribute();
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);
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。