I've seen several different posts about this issue, but none of the suggested solutions have solved my problem, which seems to indicate some fundamental misunderstanding on my behalf. I am under the impression there is a name-spacing issue between my XML and XSD, but I'm not sure how to solve it?
I'm getting the following error whilst validating my XML:
Element
'{http://www.w3.org/2001/XMLSchema}schema'
: No matching global declaration available for the validation root., line 1`
XML:
<?xml version="1.0" encoding="UTF-8"?>
<DOCUMENT_FILE
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="path\to\my.xsd">
<DOCUMENT>
<BRANCH_NUMBER>num</BRANCH_NUMBER>
</DOCUMENT>
</DOCUMENT_FILE>
XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0">
<xsd:element name="DOCUMENT_FILE">
<xsd:complexType>
<xsd:sequence minOccurs="1" maxOccurs="1">
<xsd:element name="DOCUMENT" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence minOccurs="1" maxOccurs="1">
<xsd:element name="BRANCH_NUMBER" minOccurs="1" maxOccurs="1" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
CodePudding user response:
Your XML is valid against your XSD. (Your fundamental understanding is sound.) There's likely just a minor proble in how you're specifying the path to the XSD.
XSD in same directory:
Replace
xsi:noNamespaceSchemaLocation="path\to\my.xsd">
with
xsi:noNamespaceSchemaLocation="my.xsd">
XSD in another relatively specified, local directory:
xsi:noNamespaceSchemaLocation="path/to/my.xsd">
XSD in another absolutely specified, local directory:
xsi:noNamespaceSchemaLocation="file:///path/to/my.xsd">
XSD in a remote directory:
xsi:noNamespaceSchemaLocation="https://example.com/path/to/my.xsd">
See also
- How to reference a local XML Schema file correctly?
- How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?
Update after chat: We read the error message more closely and realized that it was about a failure to validate the XSD itself, not the XML. The above tips on XSD path specification may be useful to future readers, so I'll leave this answer as-is anyway.
Bottom line: If you see a validation error regarding the schema
element, check that you're actually calling the validation routine with the XML file specified corrected and not the XSD file in its place.