validate xml schema generated manually
Question
I am trying to develop a app : Multidimensional analysis application with JSF/J2EE, I generate a Schema xml file and now i want to validate it with mondrian.xsd this my generated code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Schema description="test shcema description" name="First Schema9">
<Cube cache="true"
caption="code here"
description="cubeInSchema"
enabled="true"
name="First Cube7"/>
<Parameter defaultValue="admin"
description="parameter role"
modifiable="true"
name="param name"
type="String"/>
</Schema>
but i get this error in validation :
**cvc-complex-type.2.4.b: The content of the element "Cube" is not complete. One of the values "{Annotations, Table, View}" is expected.**
==> but i don't think that we should have a {Annotations
, Table
, View
} in each cube. I don't know how I should validate my mondrian schema.
Solution
In the mondrian.xsd XSD the Cube
element is declared as:
<xsd:element name="Cube" minOccurs="1" maxOccurs="unbounded">
...
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Annotations" type="Annotations" minOccurs="0" maxOccurs="1"/>
<xsd:group ref="FactTable" minOccurs="1" maxOccurs="1">
...
</xsd:group>
<xsd:choice minOccurs="1" maxOccurs="unbounded">
<xsd:element name="DimensionUsage" type="DimensionUsage"/>
<xsd:element name="Dimension" type="PrivateDimension"/>
</xsd:choice>
<xsd:element name="Measure" minOccurs="1" maxOccurs="unbounded">
...
From there it's declared that a chid <Annotations>
element is optional (minOccurs="0"
) but elements from the FactTable
group, a <Dimension>
or <DimensionUsage>
and a <Measure>
elements must be present, in that order.
Searching for the FactTable
group you find:
<xsd:group name="FactTable">
<xsd:choice>
<xsd:element name="Table" type="Table"/>
<xsd:element name="View" type="View"/>
</xsd:choice>
</xsd:group>
which means that the elements that are mandatory in the <Cube>
are <View>
(or <Table>
), <Dimension>
(or <DimensionUsage>
) and <Measure>
. If they are not present, your instance will not validate.
Besides that, there is an order enforced in the <Schema>
sequence: <View>
must appear after <Parameter>
(and not as in your example).
I generated a minimum validating file from the mondrian.xsd
schema, based on your file. Considering the options Dimension
and View
, all these are mandatory:
<Schema description="test shcema description" name="First Schema9">
<Parameter defaultValue="admin"
description="parameter role"
modifiable="true"
name="param name"
type="String"/>
<Cube cache="true"
caption="code here"
description="cubeInSchema"
enabled="true"
name="First Cube7">
<View alias="aaa">
<SQL dialect="sss"></SQL>
</View>
<Dimension name="bbb">
<Annotations>
<Annotation></Annotation>
</Annotations>
<Hierarchy hasAll="false">
<Level name="ccc"></Level>
</Hierarchy>
</Dimension>
<Measure name="ddd" aggregator="max"/>
</Cube>
</Schema>