MatchAttribute 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示使用文字模式比對所建立之相符項目的屬性。 此類別無法獲得繼承。
public ref class MatchAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class MatchAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type MatchAttribute = class
inherit Attribute
Public NotInheritable Class MatchAttribute
Inherits Attribute
- 繼承
- 屬性
範例
#using <System.dll>
#using <System.Web.Services.dll>
using namespace System;
using namespace System::Web::Services::Protocols;
public ref class Example_Headers
{
public:
[MatchAttribute("TITLE>(.*?)<")]
String^ Title;
[MatchAttribute("",Pattern="h1>(.*?)<",IgnoreCase=true)]
String^ H1;
[MatchAttribute("H2>((([^<,]*),?)+)<",Group=3,Capture=4)]
String^ Element;
[MatchAttribute("H2>((([^<,]*),?){2,})<",Group=3,MaxRepeats=0)]
array<String^>^ Elements1;
[MatchAttribute("H2>((([^<,]*),?){2,})<",Group=3,MaxRepeats=1)]
array<String^>^ Elements2;
[MatchAttribute("H3 ([^=]*)=([^>]*)",Group=1)]
String^ Attribute;
[MatchAttribute("H3 ([^=]*)=([^>]*)",Group=2)]
String^ Value;
};
public ref class MatchAttribute_Example: public HttpGetClientProtocol
{
public:
MatchAttribute_Example()
{
Url = "http://localhost";
}
[HttpMethodAttribute(TextReturnReader::typeid,UrlParameterWriter::typeid)]
Example_Headers^ GetHeaders()
{
return ((Example_Headers^)(Invoke( "GetHeaders", ( Url + "/MyHeaders.html" ),
gcnew array<Object^>(0) )));
}
System::IAsyncResult^ BeginGetHeaders( System::AsyncCallback^ callback,
Object^ asyncState )
{
return BeginInvoke( "GetHeaders", ( Url + "/MyHeaders.html" ),
gcnew array<Object^>(0), callback, asyncState );
}
Example_Headers^ EndGetHeaders( System::IAsyncResult^ asyncResult )
{
return (Example_Headers^)(EndInvoke( asyncResult ));
}
};
using System;
using System.Web.Services.Protocols;
public class MatchAttribute_Example : HttpGetClientProtocol
{
public MatchAttribute_Example()
{
Url = "http://localhost";
}
[HttpMethodAttribute(typeof(TextReturnReader), typeof(UrlParameterWriter))]
public Example_Headers GetHeaders()
{
return ((Example_Headers)Invoke("GetHeaders", (Url + "/MyHeaders.html"),
new object[0]));
}
public System.IAsyncResult BeginGetHeaders(System.AsyncCallback callback,
object asyncState)
{
return BeginInvoke("GetHeaders", (Url + "/MyHeaders.html"),
new object[0], callback, asyncState);
}
public Example_Headers EndGetHeaders(System.IAsyncResult asyncResult)
{
return (Example_Headers)(EndInvoke(asyncResult));
}
}
public class Example_Headers
{
[MatchAttribute("TITLE>(.*?)<")]
public string Title;
[MatchAttribute("", Pattern="h1>(.*?)<", IgnoreCase=true)]
public string H1;
[MatchAttribute("H2>((([^<,]*),?)+)<", Group=3, Capture=4)]
public string Element;
[MatchAttribute("H2>((([^<,]*),?){2,})<", Group=3, MaxRepeats=0)]
public string[] Elements1;
[MatchAttribute("H2>((([^<,]*),?){2,})<", Group=3, MaxRepeats=1)]
public string[] Elements2;
[MatchAttribute("H3 ([^=]*)=([^>]*)", Group=1)]
public string Attribute;
[MatchAttribute("H3 ([^=]*)=([^>]*)", Group=2)]
public string Value;
}
Imports System.Web.Services.Protocols
Public Class MatchAttribute_Example
Inherits HttpGetClientProtocol
Public Sub New()
Url = "http://localhost"
End Sub
<HttpMethodAttribute(GetType(TextReturnReader), GetType(UrlParameterWriter))> _
Public Function GetHeaders() As Headers
Return CType(Invoke("GetHeaders", Url + "/MyHeaders.html", New Object(0) {}), Headers)
End Function 'GetHeaders
Public Function BeginGetHeaders(ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As _
System.IAsyncResult
Return BeginInvoke("GetHeaders", Url + "/MyHeaders.html", New Object(0) {}, _
callback, asyncState)
End Function 'BeginGetHeaders
Public Function EndGetHeaders(ByVal asyncResult As System.IAsyncResult) As Headers
Return CType(EndInvoke(asyncResult), Headers)
End Function 'EndGetHeaders
End Class
Public Class Headers
<MatchAttribute("TITLE>(.*?)<")> _
Public Title As String
<MatchAttribute("", Pattern:="h1>(.*?)<", IgnoreCase:=True)> _
Public H1 As String
<MatchAttribute("H2>((([^<,]*),?)+)<", Group:=3, Capture:=4)> _
Public Element As String
<MatchAttribute("H2>((([^<,]*),?){2,})<", Group:=3, MaxRepeats:=0)> _
Public Elements1() As String
<MatchAttribute("H2>((([^<,]*),?){2,})<", Group:=3, MaxRepeats:=1)> _
Public Elements2() As String
<MatchAttribute("H3 ([^=]*)=([^>]*)", Group:=1)> _
Public Attribute As String
<MatchAttribute("H3 ([^=]*)=([^>]*)", Group:=2)> _
Public Value As String
End Class
備註
文字模式匹配允許 XML 網路服務利用現有 HTML 內容,透過正則表達式進行解析。 XML 網路服務透過匹配元素指定它想解析的服務描述內容。 這些匹配元素指定了幾個項目:解析現有 HTML 頁面內容的正則表達式、解析是否必須不區分大小寫,以及應回傳多少個與正則表達式相符的內容實例。 當客戶端使用 Wsdl.exe 工具建立代理類別時,代理類別的方法會詳細 MatchAttribute 說明服務描述中所找到的匹配元素。
欲了解更多文字模式匹配的資訊,請參閱 《如何建立解析網頁內容的網路服務》。
建構函式
| 名稱 | Description |
|---|---|
| MatchAttribute(String) |
初始化一個以指定模式的新類別實例 MatchAttribute 。 |
屬性
| 名稱 | Description |
|---|---|
| Capture |
取得或設定一個值,代表群組中匹配的索引。 |
| Group |
取得或設定一個代表相關匹配群組的值。 |
| IgnoreCase |
取得或設定一個值,指示匹配模式是否不區分大小寫。 |
| MaxRepeats |
取得或設定從配對中回傳的最大數值。 |
| Pattern |
取得或設定一個代表模式的正則表達式以匹配。 |
| TypeId |
在衍生類別中實作時,取得這個 Attribute的唯一標識碼。 (繼承來源 Attribute) |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
傳回值,這個值表示這個實例是否等於指定的物件。 (繼承來源 Attribute) |
| GetHashCode() |
傳回這個實例的哈希碼。 (繼承來源 Attribute) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| IsDefaultAttribute() |
在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。 (繼承來源 Attribute) |
| Match(Object) |
在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。 (繼承來源 Attribute) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |
明確介面實作
| 名稱 | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。 (繼承來源 Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
擷取 物件的型別資訊,可用來取得介面的類型資訊。 (繼承來源 Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
擷取物件提供的類型資訊介面數目 (0 或 1)。 (繼承來源 Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
提供物件所公開屬性和方法的存取權。 (繼承來源 Attribute) |