XmlSchemaWhiteSpaceFacet Class (System.Xml.Schema) (original) (raw)
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents the World Wide Web Consortium (W3C) whiteSpace
facet.
public ref class XmlSchemaWhiteSpaceFacet : System::Xml::Schema::XmlSchemaFacet
public class XmlSchemaWhiteSpaceFacet : System.Xml.Schema.XmlSchemaFacet
type XmlSchemaWhiteSpaceFacet = class
inherit XmlSchemaFacet
Public Class XmlSchemaWhiteSpaceFacet
Inherits XmlSchemaFacet
Inheritance
Examples
The following example shows the use of the XmlSchemaWhiteSpaceFacet
class.
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);
}
}
Imports System.Xml
Imports System.Xml.Schema
Class XMLSchemaExamples
Public Shared Sub Main()
Dim schema As New XmlSchema()
' <xs:simpleType name="NameType">
Dim NameType As New XmlSchemaSimpleType()
NameType.Name = "NameType"
' <xs:restriction base="xs:string">
Dim restriction As New XmlSchemaSimpleTypeRestriction()
restriction.BaseTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
' <xs:whiteSpace value="collapse"/>
Dim whiteSpace As New XmlSchemaWhiteSpaceFacet()
whiteSpace.Value = "collapse"
restriction.Facets.Add(whiteSpace)
NameType.Content = restriction
schema.Items.Add(NameType)
' <xs:element name="LastName" type="NameType"/>
Dim element As New XmlSchemaElement()
element.Name = "LastName"
element.SchemaTypeName = New XmlQualifiedName("NameType", "")
schema.Items.Add(element)
Dim schemaSet As New XmlSchemaSet()
AddHandler schemaSet.ValidationEventHandler, AddressOf ValidationCallbackOne
schemaSet.Add(schema)
schemaSet.Compile()
Dim compiledSchema As XmlSchema = Nothing
For Each schema1 As XmlSchema In schemaSet.Schemas()
compiledSchema = schema1
Next
Dim nsmgr As New XmlNamespaceManager(New NameTable())
nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema")
compiledSchema.Write(Console.Out, nsmgr)
End Sub
Public Shared Sub ValidationCallbackOne(ByVal sender As Object, ByVal args As ValidationEventArgs)
Console.WriteLine(args.Message)
End Sub
End Class
The following XML file is generated for the preceding code example.
<?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>
Remarks
The XmlSchemaWhiteSpaceFacet class defines how the simpleType value's white space will be treated. The whiteSpace
facet value can be one of preserve
, replace
, or collapse
.