Trouble validating a combined document
This should cover W3C XML Schema, Relax NG and DTD related problems.
Trouble validating a combined document
Here's another validation problem I'm having. I combined two XML documents into one contained in a root element. Here's the outline:
Oxygen gives this error message:
[red]http://www.w3.org/TR/xmlschema-1/#cvc-elt E cvc-elt.1: Cannot find the declaration of element 'Stock'. [/red]
Since the Stock tag is outside of any schema, shouldn't it be valid? XMLSpy doesn't complain about this file. I imagine there's something I'm doing wrong or a setting I'm not familiar with.
Code: Select all
<?xml version="1.0" ?>
<Stock>
<gr:Grills xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gr="http://grillrite.com/grills"
xsi:schemaLocation="http://grillrite.com/grills GRSchema.xsd">
[valid contents here]
</gr:Grills>
<pt:Parts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:pt="http://grillrite.com/parts"
xsi:schemaLocation="http://grillrite.com/parts PTSchema.xsd">
[valid contents here]
</pt:Parts>
</Stock>
[red]http://www.w3.org/TR/xmlschema-1/#cvc-elt E cvc-elt.1: Cannot find the declaration of element 'Stock'. [/red]
Since the Stock tag is outside of any schema, shouldn't it be valid? XMLSpy doesn't complain about this file. I imagine there's something I'm doing wrong or a setting I'm not familiar with.
Hi Steve,
The XML file you quoted above is not a valid XML document because the root element "Stock" is declared neither in a DTD nor in a schema.
According to the Xerces J parser used to validate Oxygen files:
The same error Oxygen reports is reported in XML Spy when clicking the "Validate" button located on the toolbar.
Regards, Radu.
The XML file you quoted above is not a valid XML document because the root element "Stock" is declared neither in a DTD nor in a schema.
According to the Xerces J parser used to validate Oxygen files:
So declaring schema locations for elements other than the root is an implementation limitation of the Xerces parser, see http://xml.apache.org/xerces-j/schema.html.The schema is specified by the xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute on the root element of the document. The xsi prefix must be bound to the Schema document instance namespace, as specified by the Recommendation.
The same error Oxygen reports is reported in XML Spy when clicking the "Validate" button located on the toolbar.
Regards, Radu.
Hi Steve,
Ignore my previous remark about the Xerces J limitation regarding the attribute xsi:schemaLocation appearing only in the root element.
That link was to an older Xerces implementation. With the Xerces available in the latest version of Oxygen, declaring different schema locations for different elements in the xml file is possible.
So basically all you have to do is declare a schema location for the root element of the xml file.
Regards, Radu.
Ignore my previous remark about the Xerces J limitation regarding the attribute xsi:schemaLocation appearing only in the root element.
That link was to an older Xerces implementation. With the Xerces available in the latest version of Oxygen, declaring different schema locations for different elements in the xml file is possible.
So basically all you have to do is declare a schema location for the root element of the xml file.
Regards, Radu.
Hi,
Here it is a set of files that shows a working sample.
test.xml
test.xsd
a.xsd
b.xsd
Best Regards,
George
Here it is a set of files that shows a working sample.
test.xml
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<t:test xmlns:t="test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="test test.xsd">
<a:a xmlns:a="a" xsi:schemaLocation="a a.xsd" a="1"/>
<a:b xmlns:a="b" b="2" xsi:schemaLocation="b b.xsd"/>
</t:test>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="test">
<xs:element name="test">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:any processContents="strict"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="a">
<xs:element name="a">
<xs:complexType>
<xs:attribute name="a" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="b">
<xs:element name="b">
<xs:complexType>
<xs:attribute name="b" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
George
But is it possible to have no schema or namespace for the root element while having different schemas and namespaces for the two child elements? I'm taking an XML class and the whole point of this particular exercise is that it's easy to combine two XML documents with separate schemas/namespaces into one document by using the form in my original post. According to the book (and the older version of XMLSpy that comes with the book), the code I posted is valid. But it wouldn't be the first time the book was wrong.
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