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

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > 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 クラス



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

辞書ショートカット

すべての辞書の索引

「XmlSchemaProviderAttribute クラス」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS