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

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

XmlTextWriter.WriteQualifiedName メソッド

名前空間限定名を書き込みます。このメソッドは、指定した名前空間スコープ内にあるプリフィックス検索します

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

Public Overrides Sub WriteQualifiedName
 ( _
    localName As String, _
    ns As String _
)
Dim instance As XmlTextWriter
Dim localName As String
Dim ns As String

instance.WriteQualifiedName(localName, ns)
public override void WriteQualifiedName (
    string localName,
    string ns
)
public:
virtual void WriteQualifiedName (
    String^ localName, 
    String^ ns
) override
public void WriteQualifiedName (
    String localName, 
    String ns
)
public override function WriteQualifiedName
 (
    localName : String, 
    ns : String
)

パラメータ

localName

書き込むローカル名。

ns

前に関連付ける名前空間 URI

例外例外
例外種類条件

ArgumentException

localNamenull 参照 (Visual Basic では Nothing) または String.Emptyいずれかです。

localName が、W3C名前空間仕様準拠した有効な名前ではありません。

解説解説

Microsoft Visual C# コードの例次に示します

 writer.Formatting = Formatting.Indented;
 writer.WriteStartElement("root");
  writer.WriteAttributeString("xmlns","x",null,"urn:abc");
  writer.WriteStartElement("item");
  writer.WriteStartAttribute("href",null);
  writer.WriteString("#");
  writer.WriteQualifiedName("test","urn:abc");
  writer.WriteEndAttribute();
  writer.WriteEndElement();
  writer.WriteEndElement();
  writer.Close();

次の出力生成します

 <root xmlns:x="urn:abc">
  <item href="#x:test"/>
  </root>

ns現在の既定名前空間割り当てると、プリフィックス生成されません。

属性値書き込むときに、ns が見つからないと、このメソッドプリフィックス生成します要素内容書き込むときに、ns が見つからないと、このメソッド例外スローます。

このライタ名前空間サポートしている (Namespaces が true設定されている) 場合、このメソッドは、その名前が W3C 勧告Namespaces in XML』(http://www.w3.org/TR/REC-xml-names) に準拠した有効な名前かどうか確認します

使用例使用例

XSD スキーマ一部書き込む例を次に示します

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, "http://contoso.com/po")
        
        writer.WriteStartElement("element")
        
        writer.WriteAttributeString("name", "purchaseOrder")
        
        ' Write the type attribute.
        writer.WriteStartAttribute(Nothing, "type",
 Nothing)
        writer.WriteQualifiedName("PurchaseOrder",
 "http://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

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
,"http://contoso.com/po");

     writer.WriteStartElement("element");

     writer.WriteAttributeString("name", "purchaseOrder");

     // Write the type attribute.
     writer.WriteStartAttribute(null,"type", null);
     writer.WriteQualifiedName("PurchaseOrder", "http://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);

  }

}
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlTextWriter^ writer = nullptr;
   String^ filename = "sampledata.xml";
   writer = gcnew XmlTextWriter( filename, nullptr );
   
   // Use indenting for readability.
   writer->Formatting = Formatting::Indented;
   
   // Write the root element.
   writer->WriteStartElement( "schema" );
   
   // Write the namespace declarations.
   writer->WriteAttributeString( "xmlns", nullptr, "http://www.w3.org/2001/XMLSchema"
 );
   writer->WriteAttributeString( "xmlns", "po", nullptr, "http://contoso.com/po"
 );
   writer->WriteStartElement( "element" );
   writer->WriteAttributeString( "name", "purchaseOrder" );
   
   // Write the type attribute.
   writer->WriteStartAttribute( nullptr, "type", nullptr );
   writer->WriteQualifiedName( "PurchaseOrder", "http://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 = 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 = null;
        writer = new XmlTextWriter(fileName, null);

        // Use indenting for readability.
        writer.set_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
,
            "http://contoso.com/po");
        writer.WriteStartElement("element");
        writer.WriteAttributeString("name", "purchaseOrder");

        // Write the type attribute.
        writer.WriteStartAttribute(null, "type", null);
        writer.WriteQualifiedName("PurchaseOrder", "http://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.set_PreserveWhitespace(true);

        // Load the file.
        doc.Load(fileName);

        // Write the XML content to the console.
        Console.Write(doc.get_InnerXml());
    } //main 
} //Sample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からXmlTextWriter.WriteQualifiedName メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からXmlTextWriter.WriteQualifiedName メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からXmlTextWriter.WriteQualifiedName メソッド を検索

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS