Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

XmlSchemaSimpleContent Class

Represents the simpleContent element from XML Schema as specified by the World Wide Web Consortium (W3C). This class is for simple and complex types with simple content model.

Namespace:  System.Xml.Schema
Assembly:  System.Xml (in System.Xml.dll)
public class XmlSchemaSimpleContent : XmlSchemaContentModel

The XmlSchemaSimpleContent type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkXmlSchemaSimpleContentInitializes a new instance of the XmlSchemaSimpleContent class.
Top
  NameDescription
Public propertySupported by the XNA FrameworkAnnotationGets or sets the annotation property. (Inherited from XmlSchemaAnnotated.)
Public propertySupported by the XNA FrameworkContentGets one of the XmlSchemaSimpleContentRestriction or XmlSchemaSimpleContentExtension. (Overrides XmlSchemaContentModel.Content.)
Public propertySupported by the XNA FrameworkIdGets or sets the string id. (Inherited from XmlSchemaAnnotated.)
Public propertySupported by the XNA FrameworkLineNumberGets or sets the line number in the file to which the schema element refers. (Inherited from XmlSchemaObject.)
Public propertySupported by the XNA FrameworkLinePositionGets or sets the line position in the file to which the schema element refers. (Inherited from XmlSchemaObject.)
Public propertySupported by the XNA FrameworkNamespacesGets or sets the XmlSerializerNamespaces to use with this schema object. (Inherited from XmlSchemaObject.)
Public propertySupported by the XNA FrameworkParentGets or sets the parent of this XmlSchemaObject. (Inherited from XmlSchemaObject.)
Public propertySupported by the XNA FrameworkSourceUriGets or sets the source location for the file that loaded the schema. (Inherited from XmlSchemaObject.)
Public propertySupported by the XNA FrameworkUnhandledAttributesGets or sets the qualified attributes that do not belong to the current schema's target namespace. (Inherited from XmlSchemaAnnotated.)
Top
  NameDescription
Public methodSupported by the XNA FrameworkEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkToStringReturns a string that represents the current object. (Inherited from Object.)
Top

XmlSchemaSimpleContent is used to indicate that the content model of the new type contains only character data and no elements. It does this through XmlSchemaSimpleContentExtension or XmlSchemaSimpleContentRestriction.

The following example shows the XmlSchemaSimpleContent class.

using System;
using System.Xml;
using System.Xml.Schema;

class XMLSchemaExamples
{
    public static void Main()
    {

        XmlSchema schema = new XmlSchema();

        // <xs:element name="generalPrice">
        XmlSchemaElement generalPrice = new XmlSchemaElement();
        generalPrice.Name = "generalPrice";

        // <xs:complexType>
        XmlSchemaComplexType ct = new XmlSchemaComplexType();

        // <xs:simpleContent>
        XmlSchemaSimpleContent simpleContent = new XmlSchemaSimpleContent();

        // <xs:extension base="xs:decimal">
        XmlSchemaSimpleContentExtension simpleContent_extension = new XmlSchemaSimpleContentExtension();
        simpleContent_extension.BaseTypeName = new XmlQualifiedName("decimal", "http://www.w3.org/2001/XMLSchema");

        // <xs:attribute name="currency" type="xs:string" />
        XmlSchemaAttribute currency = new XmlSchemaAttribute();
        currency.Name = "currency";
        currency.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
        simpleContent_extension.Attributes.Add(currency);

        simpleContent.Content = simpleContent_extension;
        ct.ContentModel = simpleContent;
        generalPrice.SchemaType = ct;

        schema.Items.Add(generalPrice);

        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);
    }
}

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:element name="generalPrice">
      <xs:complexType>
        <xs:simpleContent>
          <xs:extension base="xs:decimal">
            <xs:attribute name="currency" type="xs:string" />
          </xs:extension>
        </xs:simpleContent>
      </xs:complexType>
    </xs:element>
</xs:schema>

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.