SoapAttributeAttribute クラスの新しいインスタンスを初期化します。
名前空間: System.Xml.Serialization
アセンブリ: System.Xml (system.xml.dll 内)
構文
'宣言
Public Sub New
'使用
Dim instance As New SoapAttributeAttribute
public SoapAttributeAttribute ()
public:
SoapAttributeAttribute ()
public SoapAttributeAttribute ()
public function SoapAttributeAttribute ()
解説
クラス メンバのシリアル化をオーバーライドするときには、このコンストラクタを使用して SoapAttributeAttribute を作成します。SoapAttributeAttribute を作成し、そのプロパティを設定し、そのオブジェクトを SoapAttributes オブジェクトの SoapAttribute プロパティに設定します。詳細については、SoapAttributeOverrides クラスの概要を参照してください。
使用例
フィールドのシリアル化をオーバーライドするために使用する新しい SoapAttributeAttribute の作成例を次に示します。この例は、SoapAttributeAttribute を作成し、そのプロパティを設定した後で、そのオブジェクトを SoapAttributes の SoapAttribute プロパティに設定しています。次に、その SoapAttributes を、XmlSerializer を作成するために使用される SoapAttributeOverrides に追加しています。
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
Public Class Group
' This attribute will be overridden.
<SoapAttribute (Namespace: = "http://www.cpandl.com")> _
Public GroupName As String
End Class
public class Run
Public Shared Sub Main()
Dim test As Run = new Run()
test.SerializeOverride("SoapOveride.xml")
End Sub
Public Sub SerializeOverride(filename As String )
' Create an instance of the XmlSerializer class
' that overrides the serialization.
Dim overRideSerializer As XmlSerializer = _
CreateOverrideSerializer()
' Writing the file requires a TextWriter.
Dim writer As TextWriter = new StreamWriter(filename)
' Create an instance of the class that will be serialized.
Dim myGroup As Group = new Group()
' Set the object properties.
myGroup.GroupName = ".NET"
' Serialize the class, and close the TextWriter.
overRideSerializer.Serialize(writer, myGroup)
writer.Close()
End Sub
Private Function CreateOverrideSerializer() As XmlSerializer
Dim mySoapAttributeOverrides As SoapAttributeOverrides = _
New SoapAttributeOverrides()
Dim mySoapAttributes As SoapAttributes = New SoapAttributes()
' Create a new SoapAttributeAttribute to override the
' one applied to the Group class. The resulting XML
' stream will use the new namespace and attribute name.
Dim mySoapAttribute As SoapAttributeAttribute = _
New SoapAttributeAttribute()
mySoapAttribute.AttributeName = "TeamName"
' Change the Namespace.
mySoapAttribute.Namespace = "http://www.cohowinery"
mySoapAttributes.SoapAttribute = mySoapAttribute
mySoapAttributeOverrides. _
Add(GetType(Group), "GroupName" ,mySoapAttributes)
Dim myMapping As XmlTypeMapping = (new SoapReflectionImporter _
(mySoapAttributeOverrides)).ImportTypeMapping(GetType(Group))
Dim ser As XmlSerializer = new XmlSerializer(myMapping)
CreateOverrideSerializer = ser
End Function
End Class
'<?xml version="1.0" encoding="utf-8" ?>
'<Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" n1:TeamName=".NET"
'xmlns:n1="http://www.cohowinery" />
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
public class Group
{
// This attribute will be overridden.
[SoapAttribute (Namespace = "http://www.cpandl.com")]
public string GroupName;
}
public class Run
{
public static void Main()
{
Run test = new Run();
test.SerializeOverride("SoapOveride.xml");
}
public void SerializeOverride(string filename)
{
// Create an instance of the XmlSerializer class
// that overrides the serialization.
XmlSerializer overRideSerializer = CreateOverrideSerializer();
// Writing the file requires a TextWriter.
TextWriter writer = new StreamWriter(filename);
// Create an instance of the class that will be serialized.
Group myGroup = new Group();
// Set the object properties.
myGroup.GroupName = ".NET";
// Serialize the class, and close the TextWriter.
overRideSerializer.Serialize(writer, myGroup);
writer.Close();
}
private XmlSerializer CreateOverrideSerializer(){
SoapAttributeOverrides mySoapAttributeOverrides =
new SoapAttributeOverrides();
SoapAttributes mySoapAttributes = new SoapAttributes();
// Create a new SoapAttributeAttribute to override the
// one applied to the Group class. The resulting XML
// stream will use the new namespace and attribute name.
SoapAttributeAttribute mySoapAttribute =
new SoapAttributeAttribute();
mySoapAttribute.AttributeName = "TeamName";
// Change the Namespace.
mySoapAttribute.Namespace = "http://www.cohowinery.com";
mySoapAttributes.SoapAttribute = mySoapAttribute;
mySoapAttributeOverrides.
Add(typeof(Group), "GroupName" ,mySoapAttributes);
XmlTypeMapping myMapping = (new SoapReflectionImporter
(mySoapAttributeOverrides)).ImportTypeMapping(typeof(Group));
XmlSerializer ser = new XmlSerializer(myMapping);
return ser;
}
}
//<?xml version="1.0" encoding="utf-8" ?>
// <Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
//xmlns:xsd="http://www.w3.org/2001/XMLSchema" n1:TeamName=".NET"
//xmlns:n1="http://www.cohowinery" />
#using <System.Xml.dll>
#using <System.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Serialization;
public ref class Group
{
public:
// This attribute will be overridden.
[SoapAttributeAttribute(Namespace="http://www.cpandl.com")]
String^ GroupName;
};
public ref class Run
{
public:
void SerializeOverride( String^ filename )
{
// Create an instance of the XmlSerializer class
// that overrides the serialization.
XmlSerializer^ overRideSerializer = CreateOverrideSerializer();
// Writing the file requires a TextWriter.
TextWriter^ writer = gcnew StreamWriter( filename );
// Create an instance of the class that will be serialized.
Group^ myGroup = gcnew Group;
// Set the Object* properties.
myGroup->GroupName = ".NET";
// Serialize the class, and close the TextWriter.
overRideSerializer->Serialize( writer, myGroup );
writer->Close();
}
private:
XmlSerializer^ CreateOverrideSerializer()
{
SoapAttributeOverrides^ mySoapAttributeOverrides = gcnew SoapAttributeOverrides;
SoapAttributes^ mySoapAttributes = gcnew SoapAttributes;
// Create a new SoapAttributeAttribute to the
// one applied to the Group class. The resulting XML
// stream will use the new namespace and attribute name.
SoapAttributeAttribute^ mySoapAttribute = gcnew SoapAttributeAttribute;
mySoapAttribute->AttributeName = "TeamName";
// Change the Namespace.
mySoapAttribute->Namespace = "http://www.cohowinery.com";
mySoapAttributes->SoapAttribute = mySoapAttribute;
mySoapAttributeOverrides->Add( Group::typeid, "GroupName", mySoapAttributes );
XmlTypeMapping^ myMapping = (gcnew SoapReflectionImporter( mySoapAttributeOverrides ))->ImportTypeMapping( Group::typeid );
XmlSerializer^ ser = gcnew XmlSerializer( myMapping );
return ser;
}
};
int main()
{
Run^ test = gcnew Run;
test->SerializeOverride( "SoapOveride.xml" );
}
//<?xml version=S"1.0" encoding=S"utf-8" ?>
// <Group xmlns:xsi=S"http://www.w3.org/2001/XMLSchema-instance"
//xmlns:xsd=S"http://www.w3.org/2001/XMLSchema" n1:TeamName=S".NET"
//xmlns:n1=S"http://www.cohowinery" />
import System.*;
import System.IO.*;
import System.Xml.*;
import System.Xml.Serialization.*;
public class Group
{
// This attribute will be overridden.
/** @attribute SoapAttribute(Namespace = "http://www.cpandl.com")
*/
public String groupName;
} //Group
public class Run
{
public static void main(String[] args)
{
Run test = new Run();
test.SerializeOverride("SoapOveride.xml");
} //main
public void SerializeOverride(String fileName)
{
// Create an instance of the XmlSerializer class
// that overrides the serialization.
XmlSerializer overRideSerializer = CreateOverrideSerializer();
// Writing the file requires a TextWriter.
TextWriter writer = new StreamWriter(fileName);
// Create an instance of the class that will be serialized.
Group myGroup = new Group();
// Set the object properties.
myGroup.groupName = ".NET";
// Serialize the class, and close the TextWriter.
overRideSerializer.Serialize(writer, myGroup);
writer.Close();
} //SerializeOverride
private XmlSerializer CreateOverrideSerializer()
{
SoapAttributeOverrides mySoapAttributeOverrides
= new SoapAttributeOverrides();
SoapAttributes mySoapAttributes = new SoapAttributes();
// Create a new SoapAttributeAttribute to override the
// one applied to the Group class. The resulting XML
// stream will use the new namespace and attribute name.
SoapAttributeAttribute mySoapAttribute = new SoapAttributeAttribute();
mySoapAttribute.set_AttributeName("TeamName");
// Change the Namespace.
mySoapAttribute.set_Namespace("http://www.cohowinery.com");
mySoapAttributes.set_SoapAttribute(mySoapAttribute);
mySoapAttributeOverrides.Add(Group.class.ToType(), "GroupName",
mySoapAttributes);
XmlTypeMapping myMapping = (new SoapReflectionImporter(
mySoapAttributeOverrides)).ImportTypeMapping(Group.class.ToType());
XmlSerializer ser = new XmlSerializer(myMapping);
return ser;
} //CreateOverrideSerializer
} //Run
//<?xml version="1.0" encoding="utf-8" ?>
// <Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
//xmlns:xsd="http://www.w3.org/2001/XMLSchema" n1:TeamName=".NET"
//xmlns:n1="http://www.cohowinery" />
プラットフォーム
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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 2.0、1.0
参照
関連項目
SoapAttributeAttribute クラス
SoapAttributeAttribute メンバ
System.Xml.Serialization 名前空間