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

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

XmlTextWriter.LookupPrefix メソッド

名前空間 URI現在の名前空間スコープ定義されたものに最も近いプリフィックス返します

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

例外例外
例外種類条件

ArgumentException

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

解説解説
使用例使用例

book書き込む例を次に示します

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


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

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS