Schema Class
Metadata for the class corresponding to the XML element, that represents the relationship between the element and its child elements.
public sealed class Schema
- Inheritance
-
Schema
Remarks
The Schema object is the immutable list of SchemaType, and defines the possible order and number of occurrences of the child elements.
The class corresponding to the XML element that has the child elements
must have the single, static
and readonly
Schema field annotated with ElementSchemaAttribute. For example, the root element
movie
has its child elements director
and cast
as
follows:
<movie name="Avatar">
<director name="James Cameron"/>
<cast name="Sam Worthington"/>
<cast name="Zoe Saldana"/>
</movie>
The Movie
class that stands for the element movie
should be as follows:
[ForElement("movie")]
public sealed class Movie
{
[ElementSchema]
private static readonly Schema TheSchema = Schema.Of(
Mandatory.Of<Director>(),
Multiple.Of<Cast>());
[ForAttribute("name")]
private String name;
...
}
Likewise, The Director
and Cast
classes that stand for
the elements director
and cast
respectively should be as
follows:
[ForElement("director")]
public class Director { ... }
[ForElement("cast")]
public class Cast { ... }
All classes that the Schema object contains must be handled in that class with the field annotated with ForChildAttribute or the method annotated with FromChildAttribute.
The definition of the Schema object does not allow the
child element corresponding to the class T
to appear two or more
times.
Fields
Methods
Of(Schema |
Creates a new instance with the specified SchemaType objects. |
Types() |
Gets the immutable array of the SchemaType object. |
Equals(object) | (Inherited from object) |
GetHashCode() | (Inherited from object) |
GetType() | (Inherited from object) |
MemberwiseClone() | (Inherited from object) |
ToString() | (Inherited from object) |
See Also
- ElementSchemaAttribute
- ForChildAttribute
- FromChildAttribute
- SchemaType
- Mandatory.Of<T>()
- Multiple.Of<T>()
- Optional.Of<T>()
Fields Detail
Empty
An empty Schema object.
public static readonly Schema Empty
Field Value
Examples
If the class has no static
and readonly
Schema field annotated with
ElementSchemaAttribute, it is considered to be
containing no child elements. So, for example,
the MySchema
field in the Movie
class as follows
can be omitted.
[ForElement("director")]
public class Director
{
[ElementSchema]
private static readonly Schema MySchema = Schema.EMPTY;
...
}
Methods Detail
Of(SchemaType[])
Creates a new instance with the specified SchemaType objects.
public static Schema Of(params SchemaType[] args)
Parameters
- args
-
Schema
Type []
SchemaType objects.
Returns
Remarks
If the args
is empty,
returns Empty.
Types()
Gets the immutable array of the SchemaType object.
public ImmutableArray<SchemaType> Types()
Returns
The immutable array of the SchemaType object.