XmlArrayAttribute.Form プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlArrayAttribute.Form プロパティの意味・解説 

XmlArrayAttribute.Form プロパティ

XmlSerializer によって生成されXML 要素名が、修飾されているかどうかを示す値を取得または設定します

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

Dim instance As XmlArrayAttribute
Dim value As XmlSchemaForm

value = instance.Form

instance.Form = value
public XmlSchemaForm Form { get; set;
 }
public:
property XmlSchemaForm Form {
    XmlSchemaForm get ();
    void set (XmlSchemaForm value);
}
/** @property */
public XmlSchemaForm get_Form ()

/** @property */
public void set_Form (XmlSchemaForm value)
public function get Form
 () : XmlSchemaForm

public function set Form
 (value : XmlSchemaForm)

プロパティ
XmlSchemaForm 値の 1 つ既定値XmlSchemaForm.None です。

解説解説

Form プロパティは、XML 要素名が限定されているかいないかを判断しますForm プロパティは、W3C (World Wide Web Consortium) のサイト (www.w3.org) で参照できる 1999 年ドキュメントNamespaces in XML』に準拠してます。

Namespace プロパティ任意の値が設定されている場合は、Form プロパティXmlSchemaForm.Unqualified設定しようとする例外スローさます。

既定設定 XmlSchemaForm.None は、XmlSerializer対し名前空間限定されているかどうか判断するために XML ドキュメントスキーマ調べるように指示しますスキーマ個別要素または属性に値を指定しない場合XmlSerializerelementFormDefault 値および attributeFormDefault 値を使用して要素または属性限定されているかどうか判断します次の XML コードスキーマ示してます。

 <schema elementFormDefault="qualified" 
 attributeFormDefault="unqualified"... >
    <element name="Name"/>
    <attribute name="Number"/>
 </schema>

XmlSerializerスキーマ読み取ると、NameNumber両方Form 値は XmlSchemaForm.Noneなります。ただし、Name 要素修飾されますが、Number 要素修飾されません。

使用例使用例

Enterprises クラスインスタンスシリアル化する例を次に示します2 つXML 要素ローカル名が同一 (Company) ですが、プリフィックス異なってます。この例では、Form プロパティXmlForm.Qualified設定されXML インスタンス限定名が発生するようにします。

Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Schema
Imports System.Xml.Serialization



Public Class Enterprises
    Private mywineries() As Winery
    Private mycompanies() As VacationCompany
    ' Sets the Form property to qualified, and specifies the Namespace.
 
    
    <XmlArray(Form := XmlSchemaForm.Qualified, _
        ElementName := "Company", _
        Namespace := "http://www.cohowinery.com")>
 _
    Public Property Wineries() As
 Winery()
        
        Get
            Return mywineries
        End Get
        Set
            mywineries = value
        End Set
    End Property 
    
    <XmlArray(Form := XmlSchemaForm.Qualified, _
        ElementName := "Company", _
        Namespace := "http://www.treyresearch.com")>
 _ 
    Public Property Companies() As
 VacationCompany()
        
        Get
            Return mycompanies
        End Get
        Set
            mycompanies = value
        End Set
    End Property
End Class 'Enterprises
 
Public Class Winery
    Public Name As String
End Class 'Winery


Public Class VacationCompany
    Public Name As String
End Class 'VacationCompany


Public Class Run
    
    Public Shared Sub Main()
        Dim test As New
 Run()
        test.WriteEnterprises("MyEnterprises.xml")
    End Sub 'Main
    
    
    Public Sub WriteEnterprises(filename As
 String)
        ' Creates an instance of the XmlSerializer class.
        Dim mySerializer As New
 XmlSerializer(GetType(Enterprises))
        ' Writing a file requires a TextWriter.
        Dim writer As New
 StreamWriter(filename)
        
        ' Creates an instance of the XmlSerializerNamespaces class.
        Dim ns As New XmlSerializerNamespaces()
        
        ' Adds namespaces and prefixes for the XML document instance.
        ns.Add("winery", "http://www.cohowinery.com")
        ns.Add("vacationCompany", "http://www.treyresearch.com")
        
        ' Creates an instance of the class that will be serialized.
        Dim myEnterprises As New
 Enterprises()
        
        ' Creates objects and adds to the array. 
        Dim w1 As New Winery()
        w1.Name = "cohowinery"
        Dim myWinery(0) As Winery
        myWinery(0) = w1
        myEnterprises.Wineries = myWinery
        
        Dim com1 As New
 VacationCompany()
        com1.Name = "adventure-works"
        Dim myCompany(0) As VacationCompany
        myCompany(0) = com1
        myEnterprises.Companies = myCompany
        
        ' Serializes the class, and closes the TextWriter.
        mySerializer.Serialize(writer, myEnterprises, ns)
        writer.Close()
    End Sub 'WriteEnterprises
    
    
    Public Sub ReadEnterprises(filename As
 String)
        Dim mySerializer As New
 XmlSerializer(GetType(Enterprises))
        Dim fs As New FileStream(filename,
 FileMode.Open)
        Dim myEnterprises As Enterprises =
 CType(mySerializer.Deserialize(fs), Enterprises)
        
        Dim i As Integer
        For i = 0 To myEnterprises.Wineries.Length
 - 1
            Console.WriteLine(myEnterprises.Wineries(i).Name)
        Next i
        For i = 0 To myEnterprises.Companies.Length
 - 1
            Console.WriteLine(myEnterprises.Companies(i).Name)
        Next i
    End Sub 'ReadEnterprises
End Class 'Run
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
 
public class Enterprises
{
   private Winery[] wineries;
   private VacationCompany[] companies;
   // Sets the Form property to qualified, and specifies the namespace.
 
   [XmlArray(Form = XmlSchemaForm.Qualified, ElementName="Company", 
   Namespace="http://www.cohowinery.com")]
   public Winery[] Wineries{
      get{return wineries;}
      set{wineries = value;}
   }

   [XmlArray(Form = XmlSchemaForm.Qualified, ElementName = "Company", 
   Namespace = "http://www.treyresearch.com")]
   public VacationCompany [] Companies{
      get{return companies;}
      set{companies = value;}
   }
}
 
public class Winery
{
   public string Name;
}
 
public class VacationCompany{
   public string Name;
}
 
public class Run
{
   public static void Main()
   {
      Run test = new Run();
      test.WriteEnterprises("MyEnterprises.xml");
    }
 
   public void WriteEnterprises(string
 filename)
   {
      // Creates an instance of the XmlSerializer class.
      XmlSerializer mySerializer = 
      new XmlSerializer(typeof(Enterprises));
      // Writing file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Creates an instance of the XmlSerializerNamespaces class.
      XmlSerializerNamespaces ns = new XmlSerializerNamespaces();

      // Adds namespaces and prefixes for the XML document instance.
      ns.Add("winery", "http://www.cohowinery.com");
      ns.Add("vacationCompany", "http://www.treyresearch.com");

      // Creates an instance of the class that will be serialized.
      Enterprises myEnterprises = new Enterprises();
      
      // Creates objects and adds to the array. 
      Winery w1= new Winery();
      w1.Name = "cohowinery";
      Winery[]myWinery = {w1};
      myEnterprises.Wineries = myWinery;
 
      VacationCompany com1 = new VacationCompany();
      com1.Name = "adventure-works";
      VacationCompany[] myCompany = {com1};
      myEnterprises.Companies = myCompany;

      // Serializes the class, and closes the TextWriter.
      mySerializer.Serialize(writer, myEnterprises, ns);
      writer.Close();
   }

   public void ReadEnterprises(string
 filename)
   {
      XmlSerializer mySerializer = 
      new XmlSerializer(typeof(Enterprises));
      FileStream fs = new FileStream(filename, FileMode.Open);
      Enterprises myEnterprises = (Enterprises) 
      mySerializer.Deserialize(fs);
      
      for(int i = 0; i < myEnterprises.Wineries.Length;i++)
      {
         Console.WriteLine(myEnterprises.Wineries[i].Name);
      }   
      for(int i = 0; i < myEnterprises.Companies.Length;i++)
      {
         Console.WriteLine(myEnterprises.Companies[i].Name);
      }
   }
}
#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Schema;
using namespace System::Xml::Serialization;
public ref class Winery
{
public:
   String^ Name;
};

public ref class VacationCompany
{
public:
   String^ Name;
};

public ref class Enterprises
{
private:
   array<Winery^>^wineries;
   array<VacationCompany^>^companies;

public:

   // Sets the Form property to qualified, and specifies the namespace.
 
   [XmlArray(Form=XmlSchemaForm::Qualified,ElementName="Company",
   Namespace="http://www.cohowinery.com")]
   property array<Winery^>^ Wineries 
   {
      array<Winery^>^ get()
      {
         return wineries;
      }
      void set( array<Winery^>^value
 )
      {
         wineries = value;
      }
   }

   [XmlArray(Form=XmlSchemaForm::Qualified,ElementName="Company",
   Namespace="http://www.treyresearch.com")]
   property array<VacationCompany^>^ Companies 
   {
      array<VacationCompany^>^ get()
      {
         return companies;
      }
      void set( array<VacationCompany^>^value
 )
      {
         companies = value;
      }
   }
};

int main()
{
   String^ filename = "MyEnterprises.xml";

   // Creates an instance of the XmlSerializer class.
   XmlSerializer^ mySerializer = gcnew XmlSerializer( Enterprises::typeid );

   // Writing file requires a TextWriter.
   TextWriter^ writer = gcnew StreamWriter( filename );

   // Creates an instance of the XmlSerializerNamespaces class.
   XmlSerializerNamespaces^ ns = gcnew XmlSerializerNamespaces;

   // Adds namespaces and prefixes for the XML document instance.
   ns->Add( "winery", "http://www.cohowinery.com"
 );
   ns->Add( "vacationCompany", "http://www.treyresearch.com"
 );

   // Creates an instance of the class that will be serialized.
   Enterprises^ myEnterprises = gcnew Enterprises;

   // Creates objects and adds to the array. 
   Winery^ w1 = gcnew Winery;
   w1->Name = "cohowinery";
   array<Winery^>^myWinery = {w1};
   myEnterprises->Wineries = myWinery;
   VacationCompany^ com1 = gcnew VacationCompany;
   com1->Name = "adventure-works";
   array<VacationCompany^>^myCompany = {com1};
   myEnterprises->Companies = myCompany;

   // Serializes the class, and closes the TextWriter.
   mySerializer->Serialize( writer, myEnterprises, ns );
   writer->Close();
}

void ReadEnterprises( String^ filename )
{
   XmlSerializer^ mySerializer = gcnew XmlSerializer( Enterprises::typeid );
   FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
   Enterprises^ myEnterprises = dynamic_cast<Enterprises^>(mySerializer->Deserialize(
 fs ));
   for ( int i = 0; i < myEnterprises->Wineries->Length;
 i++ )
   {
      Console::WriteLine( myEnterprises->Wineries[ i ]->Name );
   }
   for ( int i = 0; i < myEnterprises->Companies->Length;
 i++ )
   {
      Console::WriteLine( myEnterprises->Companies[ i ]->Name );
   }
}
import System.*;
import System.IO.*;
import System.Xml.*;
import System.Xml.Schema.*;
import System.Xml.Serialization.*;

public class Enterprises
{
    private Winery wineries[];
    private VacationCompany companies[];

    // Sets the Form property to qualified, and specifies the namespace.
 
    /** @attribute XmlArray(Form = XmlSchemaForm.Qualified, 
        ElementName = "Company", Namespace = "http://www.cohowinery.com")
     */
    /** @property 
     */
    public Winery[] get_Wineries()
    {
        return wineries;
    } //get_Wineries

    /** @property 
     */
    public void set_Wineries(Winery value[])
    {
        wineries = value;
    } //set_Wineries

    /** @attribute XmlArray(Form = XmlSchemaForm.Qualified, 
        ElementName = "Company", Namespace = "http://www.treyresearch.com")
     */
    /** @property 
     */
    public VacationCompany[] get_Companies()
    {
        return companies;
    } //get_Companies

    /** @property 
     */
    public void set_Companies(VacationCompany
 value[])
    {
        companies = value;
    } //set_Companies
} //Enterprises

public class Winery
{
    public String name;
} //Winery

public class VacationCompany
{
    public String name;
} //VacationCompany

public class Run
{
    public static void main(String[]
 args)
    {
        Run test = new Run();
        test.WriteEnterprises("MyEnterprises.xml");
    } //main

    public void WriteEnterprises(String fileName)
    {
        // Creates an instance of the XmlSerializer class.
        XmlSerializer mySerializer = 
            new XmlSerializer(Enterprises.class.ToType());

        // Writing file requires a TextWriter.
        TextWriter writer = new StreamWriter(fileName);

        // Creates an instance of the XmlSerializerNamespaces class.
        XmlSerializerNamespaces ns = new XmlSerializerNamespaces();

        // Adds namespaces and prefixes for the XML document instance.
        ns.Add("winery", "http://www.cohowinery.com");
        ns.Add("vacationCompany", "http://www.treyresearch.com");

        // Creates an instance of the class that will be serialized.
        Enterprises myEnterprises = new Enterprises();

        // Creates objects and adds to the array. 
        Winery w1 = new Winery();
        w1.name = "cohowinery";
        Winery myWinery[] = { w1 };
        myEnterprises.set_Wineries(myWinery);

        VacationCompany com1 = new VacationCompany();
        com1.name = "adventure-works";
        VacationCompany myCompany[] = { com1 };
        myEnterprises.set_Companies(myCompany);

        // Serializes the class, and closes the TextWriter.
        mySerializer.Serialize(writer, myEnterprises, ns);
        writer.Close();
    } //WriteEnterprises

    public void ReadEnterprises(String fileName)
    {
        XmlSerializer mySerializer = 
            new XmlSerializer(Enterprises.class.ToType());
        FileStream fs = new FileStream(fileName, FileMode.Open);
        Enterprises myEnterprises = 
            (Enterprises)(mySerializer.Deserialize(fs));

        for (int i = 0; i < myEnterprises.get_Wineries().length;
 i++) {
            Console.WriteLine(((Winery)myEnterprises.get_Wineries().
                get_Item(i)).name);
        }

        for (int i = 0; i < myEnterprises.get_Companies().length;
 i++) {
            Console.WriteLine(((VacationCompany)myEnterprises.get_Companies().
                get_Item(i)).name);
        }
    } //ReadEnterprises
} //Run
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlArrayAttribute クラス
XmlArrayAttribute メンバ
System.Xml.Serialization 名前空間
XmlSerializer
Serialize
XmlArrayAttribute.ElementName プロパティ
Namespace



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

辞書ショートカット

すべての辞書の索引

「XmlArrayAttribute.Form プロパティ」の関連用語

XmlArrayAttribute.Form プロパティのお隣キーワード
検索ランキング

   

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



XmlArrayAttribute.Form プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS