XsltMessageEncounteredEventArgs Klasa
Definicja
Ważny
Niektóre informacje dotyczą produktów przedpremierowych, które mogą zostać znacznie zmodyfikowane przed premierą. Microsoft nie udziela żadnych gwarancji, ani wyraźnych, ani domniemanych, dotyczących informacji podanych tutaj.
Udostępnia dane dla zdarzenia XsltMessageEncountered.
public ref class XsltMessageEncounteredEventArgs abstract : EventArgs
public abstract class XsltMessageEncounteredEventArgs : EventArgs
type XsltMessageEncounteredEventArgs = class
inherit EventArgs
Public MustInherit Class XsltMessageEncounteredEventArgs
Inherits EventArgs
- Dziedziczenie
Przykłady
W poniższym przykładzie użyto elementu , XsltMessageEncounteredEventArgs aby wyświetlić xsl:message zawartość w konsoli programu . W przykładzie do konsoli jest zapisywany następujący komunikat: Message received: Author name is not in the correct format <author><name>Plato</name></author>.
using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
public class Sample {
public static void Main() {
// Create the XslCompiledTransform object and load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("message.xsl");
XsltArgumentList argList = new XsltArgumentList();
argList.XsltMessageEncountered += new XsltMessageEncounteredEventHandler(MessageCallBack);
// Load the file to transform.
XPathDocument doc = new XPathDocument("books.xml");
// Transform the file.
xslt.Transform(doc, argList, XmlWriter.Create("output.xml"));
}
private static void MessageCallBack(object sender, XsltMessageEncounteredEventArgs e) {
Console.WriteLine("Message received: {0}", e.Message);
}
}
Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Xml.XPath
Public Class Sample
Public Shared Sub Main()
' Create the XslCompiledTransform object and load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("message.xsl")
Dim argList As New XsltArgumentList()
AddHandler argList.XsltMessageEncountered, AddressOf MessageCallBack
' Load the file to transform.
Dim doc As New XPathDocument("books.xml")
' Transform the file.
xslt.Transform(doc, argList, XmlWriter.Create("output.xml"))
End Sub
Private Shared Sub MessageCallBack(ByVal sender As Object, ByVal e As XsltMessageEncounteredEventArgs)
Console.WriteLine("Message received: {0}", e.Message)
End Sub
End Class
W przykładzie użyto następujących plików jako danych wejściowych:
books.xml
<bookstore>
<book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>
message.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="*"/>
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="*">
<xsl:apply-templates select="//author"/>
</xsl:template>
<xsl:template match="author">
<xsl:if test="not (last-name)">
<xsl:message terminate="no">Author name is not in the correct format <xsl:copy-of select="."/>
</xsl:message>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Uwagi
Zdarzenie występuje podczas przetwarzania XsltMessageEncountered XSLT, gdy element xsl:message jest określony w arkuszu stylów.
Uwaga
terminate Jeśli atrybut jest ustawiony na "yes"wartość , procesor XSLT zatrzymuje wykonywanie arkusza stylów po przetworzeniu komunikatu.
Konstruktorów
| Nazwa | Opis |
|---|---|
| XsltMessageEncounteredEventArgs() |
Inicjuje nowe wystąpienie klasy XsltMessageEncounteredEventArgs. |
Właściwości
| Nazwa | Opis |
|---|---|
| Message |
Pobiera zawartość |
Metody
| Nazwa | Opis |
|---|---|
| Equals(Object) |
Określa, czy dany obiekt jest taki sam, jak bieżący obiekt. (Dziedziczone od Object) |
| GetHashCode() |
Służy jako domyślna funkcja skrótu. (Dziedziczone od Object) |
| GetType() |
Type Pobiera wartość bieżącego wystąpienia. (Dziedziczone od Object) |
| MemberwiseClone() |
Tworzy płytkią kopię bieżącego Objectelementu . (Dziedziczone od Object) |
| ToString() |
Zwraca ciąg reprezentujący bieżący obiekt. (Dziedziczone od Object) |