Michael_D
asked on
Simple xfd - URGENT
I have 3 elements - lets call them <root>, <group> and <entry>
<root> - the document's root element - can contain ANY amount of <group> and <entry> elements in ANY order
<group> also can contain ANY amount of <group> and <entry> elements in ANY order
so this is valid xml doc for me
<root>
<entry>this is the entry</entry>
<group>
<entry>this is the entry</entry>
<entry>this is the entry</entry>
<group>
<entry>this is the entry</entry>
</group>
<group>
<entry>this is the entry</entry>
<group></group>
</root>
I need to create xfd schema for this scenario
This is very URGENT!!!
Thanks
<root> - the document's root element - can contain ANY amount of <group> and <entry> elements in ANY order
<group> also can contain ANY amount of <group> and <entry> elements in ANY order
so this is valid xml doc for me
<root>
<entry>this is the entry</entry>
<group>
<entry>this is the entry</entry>
<entry>this is the entry</entry>
<group>
<entry>this is the entry</entry>
</group>
<group>
<entry>this is the entry</entry>
<group></group>
</root>
I need to create xfd schema for this scenario
This is very URGENT!!!
Thanks
ASKER
Doesn't <xs:sequence> mean that elements should come in exact order?
ASKER
I can't believe that it impossible to do!!!!
It seems to be so simple!
I must be missing something.
Here is my actual xsd file (with attributes and so on...)
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualif ied" attributeFormDefault="unqu alified">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="group" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="entry" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="start" type="xs:dateTime" use="required"/>
<xs:attribute name="end" type="xs:dateTime" use="required"/>
<xs:attribute name="lastgroup" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="group">
<xs:complexType>
<xs:sequence>
<xs:element ref="entry" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="group" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="desc"/>
</xs:complexType>
</xs:element>
<xs:element name="entry" type="xs:anyType"/>
<xs:simpleType name="severity">
<xs:restriction base="xs:string">
<xs:enumeration value="Fatal"/>
<xs:enumeration value="Error"/>
<xs:enumeration value="Warning"/>
<xs:enumeration value="Info"/>
<xs:enumeration value="Trace"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
And this XLM is perfectly valid for me but doesn't pass the xsd validation:
<?xml version="1.0" encoding="UTF-8"?>
<root start="2006-01-01T13:55:12 " end="2006-01-01T13:55:12" lastgroup="0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocat ion="log.x sd">
<group desc="some descr">
<entry ts="2006-01-01T13:55:12" src="" sev="Error">this is an entry</entry>
<group>
<entry ts="2006-01-01T13:55:12" src="" sev="Error">this is an entry</entry>
</group>
</group>
<entry ts="2006-01-01T13:55:12" src="" sev="Error">this is an entry</entry>
<group>
<group>
<entry ts="2006-01-01T13:55:12" src="" sev="Error">this is an entry</entry>
</group>
<entry ts="2006-01-01T13:55:12" src="" sev="Error">this is an entry</entry>
</group>
<entry ts="2006-01-01T13:55:12" src="" sev="Error">this is an entry</entry>
<entry ts="2006-01-01T13:55:12" src="" sev="Error">this is an entry</entry>
</root>
It seems to be so simple!
I must be missing something.
Here is my actual xsd file (with attributes and so on...)
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualif
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="group" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="entry" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="start" type="xs:dateTime" use="required"/>
<xs:attribute name="end" type="xs:dateTime" use="required"/>
<xs:attribute name="lastgroup" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="group">
<xs:complexType>
<xs:sequence>
<xs:element ref="entry" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="group" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="desc"/>
</xs:complexType>
</xs:element>
<xs:element name="entry" type="xs:anyType"/>
<xs:simpleType name="severity">
<xs:restriction base="xs:string">
<xs:enumeration value="Fatal"/>
<xs:enumeration value="Error"/>
<xs:enumeration value="Warning"/>
<xs:enumeration value="Info"/>
<xs:enumeration value="Trace"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
And this XLM is perfectly valid for me but doesn't pass the xsd validation:
<?xml version="1.0" encoding="UTF-8"?>
<root start="2006-01-01T13:55:12
<group desc="some descr">
<entry ts="2006-01-01T13:55:12" src="" sev="Error">this is an entry</entry>
<group>
<entry ts="2006-01-01T13:55:12" src="" sev="Error">this is an entry</entry>
</group>
</group>
<entry ts="2006-01-01T13:55:12" src="" sev="Error">this is an entry</entry>
<group>
<group>
<entry ts="2006-01-01T13:55:12" src="" sev="Error">this is an entry</entry>
</group>
<entry ts="2006-01-01T13:55:12" src="" sev="Error">this is an entry</entry>
</group>
<entry ts="2006-01-01T13:55:12" src="" sev="Error">this is an entry</entry>
<entry ts="2006-01-01T13:55:12" src="" sev="Error">this is an entry</entry>
</root>
ASKER
OK i found it by myself:
Here is valid schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualif ied" attributeFormDefault="unqu alified">
<xs:element name="root">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="group" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="entry" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
<xs:attribute name="start" type="xs:dateTime" use="required"/>
<xs:attribute name="end" type="xs:dateTime" use="required"/>
<xs:attribute name="lastgroup" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="group">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="entry" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="group" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
<xs:attribute name="desc"/>
</xs:complexType>
</xs:element>
<xs:element name="entry" type="xs:anyType"/>
<xs:simpleType name="severity">
<xs:restriction base="xs:string">
<xs:enumeration value="Fatal"/>
<xs:enumeration value="Error"/>
<xs:enumeration value="Warning"/>
<xs:enumeration value="Info"/>
<xs:enumeration value="Trace"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
I will leave this topic open for some time in case if one of the experts want to improve this or point to a error
Thanks
Here is valid schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualif
<xs:element name="root">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="group" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="entry" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
<xs:attribute name="start" type="xs:dateTime" use="required"/>
<xs:attribute name="end" type="xs:dateTime" use="required"/>
<xs:attribute name="lastgroup" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="group">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="entry" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="group" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
<xs:attribute name="desc"/>
</xs:complexType>
</xs:element>
<xs:element name="entry" type="xs:anyType"/>
<xs:simpleType name="severity">
<xs:restriction base="xs:string">
<xs:enumeration value="Fatal"/>
<xs:enumeration value="Error"/>
<xs:enumeration value="Warning"/>
<xs:enumeration value="Info"/>
<xs:enumeration value="Trace"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
I will leave this topic open for some time in case if one of the experts want to improve this or point to a error
Thanks
Michael_D,
> Doesn't <xs:sequence> mean that elements should come in exact order?
yes,
if you don't want that to happen, use <xs:choice>
if you want them mixed, like this
<entry/>
<group/>
<entry/>
<group>
put a maxOccurs on the choice instead of on the element references
like this
<xs:element name="root">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="entry" />
<xs:element ref="group" />
</xs:choice>
</xs:complexType>
</xs:element>
cheers
Geert
> Doesn't <xs:sequence> mean that elements should come in exact order?
yes,
if you don't want that to happen, use <xs:choice>
if you want them mixed, like this
<entry/>
<group/>
<entry/>
<group>
put a maxOccurs on the choice instead of on the element references
like this
<xs:element name="root">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="entry" />
<xs:element ref="group" />
</xs:choice>
</xs:complexType>
</xs:element>
cheers
Geert
Michael_D,
> Here is valid schema:
well, I had to leave after my first post,
seems you found the solution to your later question yourself
one small comment on your schema
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="entry" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="group" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
you don't need to specify the Occurence indicators on the element references
I would definitely change this into
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="entry" />
<xs:element ref="group" />
</xs:choice>
It does exactly the same thing, but makes it more clear to the parser
If you have a sequence <entry/><entry/> in your XML...
is this one time the choice group with two times the entry element
or is this two times the choice group with each one of them a single entry
this doesn't really matter, but if you start deriving from this model,
you could hit the wall of the unique particle rule earlier
keep your schema simple.
no further comments...
except, maybe you could make the complexType a named type and reference it in both root and group,
I didn't do that in my original schema, to make it not too complex,
but I would in a final schema... having duplicates of code snippets is never a good thing
cheers
Geert
> Here is valid schema:
well, I had to leave after my first post,
seems you found the solution to your later question yourself
one small comment on your schema
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="entry" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="group" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
you don't need to specify the Occurence indicators on the element references
I would definitely change this into
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="entry" />
<xs:element ref="group" />
</xs:choice>
It does exactly the same thing, but makes it more clear to the parser
If you have a sequence <entry/><entry/> in your XML...
is this one time the choice group with two times the entry element
or is this two times the choice group with each one of them a single entry
this doesn't really matter, but if you start deriving from this model,
you could hit the wall of the unique particle rule earlier
keep your schema simple.
no further comments...
except, maybe you could make the complexType a named type and reference it in both root and group,
I didn't do that in my original schema, to make it not too complex,
but I would in a final schema... having duplicates of code snippets is never a good thing
cheers
Geert
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for the correction
welcome
I assume you mean xsd
This should get you started
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="entry" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="group" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="group">
<xs:complexType>
<xs:sequence>
<xs:element ref="entry" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="group" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="entry"/>
</xs:schema>
Cheers!