XSD for > 1 alternative root element?
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 43
- Joined: Tue Jul 26, 2016 6:31 pm
XSD for > 1 alternative root element?
Hi all,
I've come across this supposed possibility for enabling validation of 2 different XML documents using 1 schema:
https://stackoverflow.com/questions/116 ... -at-a-time
Is this a documented feature of XML schema?
I've come across this supposed possibility for enabling validation of 2 different XML documents using 1 schema:
https://stackoverflow.com/questions/116 ... -at-a-time
Is this a documented feature of XML schema?
-
- Posts: 43
- Joined: Tue Jul 26, 2016 6:31 pm
Re: XSD for > 1 alternative root element?
I verified in oxygen that this type of schema does in fact validate alternate root xml instances.
I discovered it also seems to imply that XSDs which use the "ref" attribute to define child elements also end up allowing those elements as possible root elements e.g.
It allows roots `<a>`, `<b>` but also `<child>`...
This is based on a schema auto-generated by oxygen BTW so maybe you want to think if this is the best way to generate these?
I discovered it also seems to imply that XSDs which use the "ref" attribute to define child elements also end up allowing those elements as possible root elements e.g.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="b">
<xs:complexType>
<xs:sequence>
<xs:element ref="child" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="a">
<xs:complexType>
<xs:sequence>
<xs:element ref="child" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="child">
<xs:complexType />
</xs:element>
</xs:schema>
This is based on a schema auto-generated by oxygen BTW so maybe you want to think if this is the best way to generate these?
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: XSD for > 1 alternative root element?
Hi,
Any global element (declared at top level) of the schema can be used as root. The XML validation simply checks that all components adhere to the schema, starting from whatever root the XML provides.
Oxygen uses Trang for generating XML schema from XML instances. Trang prefers to declare the elements as global, rather than making them local.
This makes it easy to reuse/rewrite the generated schema.
Sorry, what's the question here? Are you asking why the generated schema allows multiple possible roots?
Regards,
Adrian
Any global element (declared at top level) of the schema can be used as root. The XML validation simply checks that all components adhere to the schema, starting from whatever root the XML provides.
Oxygen uses Trang for generating XML schema from XML instances. Trang prefers to declare the elements as global, rather than making them local.
This makes it easy to reuse/rewrite the generated schema.
Sorry, what's the question here? Are you asking why the generated schema allows multiple possible roots?
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service