XmlSchemaProviderAttributeとは? わかりやすく解説

XmlSchemaProviderAttribute クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

型に適用され場合XML スキーマ返す型の静的メソッドの名前と、型のシリアル化制御する XmlQualifiedName を格納します

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

<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Struct
 Or AttributeTargets.Interface)> _
Public NotInheritable Class
 XmlSchemaProviderAttribute
    Inherits Attribute
Dim instance As XmlSchemaProviderAttribute
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Interface)]
 
public sealed class XmlSchemaProviderAttribute
 : Attribute
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Interface)]
 
public ref class XmlSchemaProviderAttribute
 sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Interface)
 */ 
public final class XmlSchemaProviderAttribute
 extends Attribute
AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Interface)
 
public final class XmlSchemaProviderAttribute
 extends Attribute
解説解説

XmlSchemaProviderAttribute主な役目は、Web サービス記述言語ツール (WSDL.exe) から問い合わせがあった場合、または Visual Studio の [Web 参照追加] 機能使用する場合に、XmlSchemaExporter クラススキーマ返せるようにすることです。型の実際スキーマ制御静的メソッドで行うことができます

メモメモ

この属性ターゲット クラスは IXmlSerializable インターフェイス実装する必要があります

MethodName プロパティは、リフレクションを介して静的メソッドの名前を返します実装必要があるこのメソッドは、単一パラメータである XmlSchemaSet オブジェクト使用する必要があります。このメソッドは、このオブジェクトXmlSchema オブジェクト読み込みます。またこのメソッドは、データ型識別する XmlQualifiedName オブジェクト返す必要もあります

使用例使用例

次の例では、XmlSchemaProviderAttributeサーバー側のクラス適用してます。呼び出しを行うと、MethodName プロパティによって名前が指定されているメソッドスキーマ作成します。この単純な実装では、ディスクから既存スキーマ読み込みます。ただし、System.Xml.Schema 名前空間にある型を使用すると、必要に応じてカスタム スキーマ作成できます

<XmlSchemaProvider("MySchema")>  _
Public Class SongStream
    Implements IXmlSerializable
    
    Private Const ns As
 String = "http://demos.Contoso.com/webservices"
    Private filePath As String
    
    Public Sub New() 
    
    End Sub
     
    Public Sub New(ByVal
 filePath As String) 
        Me.filePath = filePath
    End Sub
    
    
    ' This is the method named by the XmlSchemaProviderAttribute applied
 to the type.
    Public Shared Function
 MySchema(ByVal xs As XmlSchemaSet) As
 XmlQualifiedName 
        ' This method is called by the framework to get the schema for
 this type.
        ' We return an existing schema from disk.
        Dim schemaSerializer As New
 XmlSerializer(GetType(XmlSchema))
        Dim xsdPath As String
 = Nothing
        ' NOTE: replace SongStream.xsd with your own schema file.
        xsdPath = System.Web.HttpContext.Current.Server.MapPath("SongStream.xsd")
        Dim s As XmlSchema = CType(schemaSerializer.Deserialize(New
 XmlTextReader(xsdPath)), XmlSchema)
        xs.XmlResolver = New XmlUrlResolver()
        xs.Add(s)
        
        Return New XmlQualifiedName("songStream",
 ns)
    
    End Function
    
    
    
    Sub WriteXml(ByVal writer As
 System.Xml.XmlWriter)  Implements IXmlSerializable.WriteXml
        ' This is the chunking code.
        ' ASP.NET buffering must be turned off for this to work.
        
        Dim bufferSize As Integer
 = 4096
        Dim songBytes(bufferSize) As Char
        Dim inFile As FileStream = File.Open(Me.filePath,
 FileMode.Open, FileAccess.Read)
        
        Dim length As Long
 = inFile.Length
        
        ' Write the file name.
        writer.WriteElementString("fileName", ns,
 Path.GetFileNameWithoutExtension(Me.filePath))
        
        ' Write the size.
        writer.WriteElementString("size", ns, length.ToString())
        
        ' Write the song bytes.
        writer.WriteStartElement("song", ns)
        
        Dim sr As New StreamReader(inFile,
 True)
        Dim readLen As Integer
 = sr.Read(songBytes, 0, bufferSize)
        
        While readLen > 0
            writer.WriteStartElement("chunk", ns)
            writer.WriteChars(songBytes, 0, readLen)
            writer.WriteEndElement()
            
            writer.Flush()
            readLen = sr.Read(songBytes, 0, bufferSize)
        End While
        
        writer.WriteEndElement()
        inFile.Close()
    End Sub 
        
    Function GetSchema() As System.Xml.Schema.XmlSchema
  Implements IXmlSerializable.GetSchema
        Throw New System.NotImplementedException()
    End Function
    
    Sub ReadXml(ByVal reader As
 System.Xml.XmlReader)  Implements IXmlSerializable.ReadXml
        Throw New System.NotImplementedException()
    End Sub 
End Class 

[XmlSchemaProvider("MySchema")]
public class SongStream : IXmlSerializable
{

    private const string
 ns = "http://demos.Contoso.com/webservices";
    private string filePath;

    public SongStream(){ }

    public SongStream(string filePath)
    {
     this.filePath = filePath;
    }

    // This is the method named by the XmlSchemaProviderAttribute applied
 to the type.
    public static XmlQualifiedName MySchema(XmlSchemaSet
 xs)
    {
     // This method is called by the framework to get the schema for
 this type.
     // We return an existing schema from disk.

     XmlSerializer schemaSerializer = new XmlSerializer(typeof(XmlSchema));
     string xsdPath = null;
     // NOTE: replace the string with your own path.
     xsdPath = System.Web.HttpContext.Current.Server.MapPath("SongStream.xsd");
     XmlSchema s = (XmlSchema)schemaSerializer.Deserialize(
         new XmlTextReader(xsdPath), null);
     xs.XmlResolver = new XmlUrlResolver();
     xs.Add(s);

     return new XmlQualifiedName("songStream",
 ns);
    }


    void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer)
    {
       // This is the chunking code.
       // ASP.NET buffering must be turned off for this to work.
 

     int bufferSize = 4096;
     char[] songBytes = new char[bufferSize];
     FileStream inFile = File.Open(this.filePath, FileMode.Open,
 FileAccess.Read);

     long length = inFile.Length;

     // Write the file name.
     writer.WriteElementString("fileName", ns, Path.GetFileNameWithoutExtension(this.filePath));

     // Write the size.
     writer.WriteElementString("size", ns, length.ToString());

     // Write the song bytes.
     writer.WriteStartElement("song", ns);

     StreamReader sr = new StreamReader(inFile, true);
     int readLen = sr.Read(songBytes, 0, bufferSize);

     while (readLen > 0)
     {
         writer.WriteStartElement("chunk", ns);
         writer.WriteChars(songBytes, 0, readLen);
         writer.WriteEndElement();

         writer.Flush();
         readLen = sr.Read(songBytes, 0, bufferSize);
     }

     writer.WriteEndElement();
     inFile.Close();

    }


    System.Xml.Schema.XmlSchema IXmlSerializable.GetSchema()
    {
     throw new System.NotImplementedException();
    }

    void IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
    {
     throw new System.NotImplementedException();

    }
}
継承階層継承階層
System.Object
   System.Attribute
    System.Xml.Serialization.XmlSchemaProviderAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlSchemaProviderAttribute メンバ
System.Xml.Serialization 名前空間
XmlSchema クラス
XmlSchemaSet クラス
XmlReflectionImporter クラス

XmlSchemaProviderAttribute コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

型の XML スキーマ提供する静的メソッドの名前を受け取って、XmlSchemaProviderAttribute クラス新しインスタンス初期化します。

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

Public Sub New ( _
    methodName As String _
)
Dim methodName As String

Dim instance As New XmlSchemaProviderAttribute(methodName)
public XmlSchemaProviderAttribute (
    string methodName
)
public:
XmlSchemaProviderAttribute (
    String^ methodName
)
public XmlSchemaProviderAttribute (
    String methodName
)
public function XmlSchemaProviderAttribute
 (
    methodName : String
)

パラメータ

methodName

実装する必要がある静的メソッドの名前。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlSchemaProviderAttribute クラス
XmlSchemaProviderAttribute メンバ
System.Xml.Serialization 名前空間

XmlSchemaProviderAttribute プロパティ


パブリック プロパティパブリック プロパティ

参照参照

関連項目

XmlSchemaProviderAttribute クラス
System.Xml.Serialization 名前空間
XmlSchema クラス
XmlSchemaSet クラス
XmlReflectionImporter クラス

XmlSchemaProviderAttribute メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用され指定した型のカスタム属性取得します。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されカスタム属性配列取得します。 ( Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスハッシュ コード返します。 ( Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラス既定値かどうか示します。 ( Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます指定した型のカスタム属性が、アセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されているかどうか判断します。 ( Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンス等しかどうかを示す値を返します。 ( Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

XmlSchemaProviderAttribute クラス
System.Xml.Serialization 名前空間
XmlSchema クラス
XmlSchemaSet クラス
XmlReflectionImporter クラス

XmlSchemaProviderAttribute メンバ

型に適用され場合XML スキーマ返す型の静的メソッドの名前と、型のシリアル化制御する XmlQualifiedName を格納します

XmlSchemaProviderAttribute データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド XmlSchemaProviderAttribute 型の XML スキーマ提供する静的メソッドの名前を受け取って、XmlSchemaProviderAttribute クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用され指定した型のカスタム属性取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されカスタム属性配列取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスハッシュ コード返します。 (Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラス既定値かどうか示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます指定した型のカスタム属性が、アセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されているかどうか判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンス等しかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

XmlSchemaProviderAttribute クラス
System.Xml.Serialization 名前空間
XmlSchema クラス
XmlSchemaSet クラス
XmlReflectionImporter クラス


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

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

辞書ショートカット

すべての辞書の索引

「XmlSchemaProviderAttribute」の関連用語

XmlSchemaProviderAttributeのお隣キーワード
検索ランキング

   

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



XmlSchemaProviderAttributeのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS