Page 1 of 1

Valid Schema by itself?

Posted: Thu Mar 16, 2006 10:27 pm
by ychaikin
Hi,

In OxygenXML, is there a way to tell if the schema defined in a particular file is not a valid schema if it were to be used by itself? For example, if the schema defined a bunch of child elements and never defined the root element, the resulting document would not be well-formed. So, it stands to reason that a parser of the schema should be able to detect that sort of thing.

Does OxygenXML do this?

Thanks,
Yaakov.

Posted: Fri Mar 17, 2006 3:01 pm
by george
Hi Yakoov,

XML Schema documents need to be each one valid. XML Schema has no notion of root element, a schema defines global and local elements. Any global element can be used as a root element in a document that can be validated against that schema.

Best Regards,
George

Posted: Fri Mar 17, 2006 5:49 pm
by ychaikin
Are you saying that XML Schema can not enforse some particular element to be the root element in an instance XML document?

Posted: Fri Mar 17, 2006 6:00 pm
by george
Exactly, all the elements that are defined as global elements in W3C XML Schema can be used as root elements in a document. This is true also for DTDs where all the elements can be used as root element. Relax NG defines a start pattern that contains the name class that mathes the possible root elements, it also allows more possible root elements.

Best regards,
George

Posted: Fri Mar 17, 2006 6:34 pm
by ychaikin
Yes, but XML Schema doesn't force you to define every element as global element. You can define 1 global element and define the rest of the things as just types that contain elements of some other types and so on. This way, you CAN enforce that only 1 element be the root element and sort of express the fact that the XML document has to be well-formed.

Am I wrong about this?

However, I do see the point you are making regarding my original question... Just as a side... Why does XML Schema inherently allow constructs that can result in a no well-formed documents?

Posted: Fri Mar 17, 2006 6:44 pm
by george
XML Schema does not have any impact in the wellformedness of a document. XML Schema defines only validity for a document. If a document is not wellformed then it is not an XML document.
So I do not understand your question. XML Schema specifies some constraints and it is used in a validation process on a wellformed, (that means XML) document. There are no constructs in XML Schema that can result in not wellformed documents.

Best Regards,
George

Posted: Fri Mar 17, 2006 7:06 pm
by ychaikin
Sorry... I am not explaining myself clearly...

Yes, I understand that validation doesn't even come into the picture if the document is not well-formed. The question I was wondering about is why even allow more than one global element in an XML Schema? You can just define a root element with a "choice".

However, if I understand you correctly, you are saying that defining multiple global elements is, in fact, the only way to define that you want to allow a CHOICE of the root element itself.

Is that correct?

Thanks,
Yaakov.

Posted: Fri Mar 17, 2006 10:38 pm
by george
Hi Yaakov,

There are more considerations to define global elements than to have those elements used as root elements in an instance document. Local elements for instance cannot be referred, so if you have XHTML and XForms embedded in XHTML then you want many of the XForms elements to be global in order to be able to allow them inside the XHTML document in different places where thay can appear.
Another use is for instance when you want to XInclude content and you want to use the schema to validate also the included fragments, so you want to have more global elements than the root of the master document.

Best Regards,
George