XmlSchemaWhiteSpaceFacet-Klasse
.NET Framework 3.5
Aktualisiert: November 2007
Stellt das W3C-whiteSpace-Facet (World Wide Web Consortium) dar.
Assembly: System.Xml (in System.Xml.dll)
Das folgende Beispiel veranschaulicht die Verwendung der XmlSchemaWhiteSpaceFacet-Klasse.
using System; using System.Xml; using System.Xml.Schema; class XMLSchemaExamples { public static void Main() { XmlSchema schema = new XmlSchema(); // <xs:simpleType name="NameType"> XmlSchemaSimpleType NameType = new XmlSchemaSimpleType(); NameType.Name = "NameType"; // <xs:restriction base="xs:string"> XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction(); restriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // <xs:whiteSpace value="collapse"/> XmlSchemaWhiteSpaceFacet whiteSpace = new XmlSchemaWhiteSpaceFacet(); whiteSpace.Value = "collapse"; restriction.Facets.Add(whiteSpace); NameType.Content = restriction; schema.Items.Add(NameType); // <xs:element name="LastName" type="NameType"/> XmlSchemaElement element = new XmlSchemaElement(); element.Name = "LastName"; element.SchemaTypeName = new XmlQualifiedName("NameType", ""); schema.Items.Add(element); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne); schemaSet.Add(schema); schemaSet.Compile(); XmlSchema compiledSchema = null; foreach (XmlSchema schema1 in schemaSet.Schemas()) { compiledSchema = schema1; } XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); compiledSchema.Write(Console.Out, nsmgr); } public static void ValidationCallbackOne(object sender, ValidationEventArgs args) { Console.WriteLine(args.Message); } }
Für das vorhergehende Codebeispiel wird die folgende XML-Datei generiert.
<?xml version="1.0" encoding="IBM437"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:simpleType name="NameType"> <xs:restriction base="xs:string"> <xs:whiteSpace value="collapse"/> </xs:restriction> </xs:simpleType> <xs:element name="LastName" type="NameType"/> </xs:schema>
System.Object
System.Xml.Schema.XmlSchemaObject
System.Xml.Schema.XmlSchemaAnnotated
System.Xml.Schema.XmlSchemaFacet
System.Xml.Schema.XmlSchemaWhiteSpaceFacet
System.Xml.Schema.XmlSchemaObject
System.Xml.Schema.XmlSchemaAnnotated
System.Xml.Schema.XmlSchemaFacet
System.Xml.Schema.XmlSchemaWhiteSpaceFacet
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile für Smartphone, Windows Mobile für Pocket PC, Xbox 360
.NET Framework und .NET Compact Framework unterstützen nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.