Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meaning of 'Schemas validation error' #31

Open
paulhiggs opened this issue Dec 1, 2019 · 1 comment
Open

Meaning of 'Schemas validation error' #31

paulhiggs opened this issue Dec 1, 2019 · 1 comment

Comments

@paulhiggs
Copy link

paulhiggs commented Dec 1, 2019

I am trying to use xmllint to validate an XML document against a set of schemas and get the following error:

{
  errors: [
    "file_0.xml:26: element ServiceList: Schemas validity error : Element '{urn:dvb:metadata:servicediscovery:2019}ServiceList': No matching global declaration available for the validation root."
  ]
}

Line 26 of the XML document is

<ServiceList xmlns="urn:dvb:metadata:servicediscovery:2019" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tva="urn:tva:metadata:2019" version="191126165755" xsi:schemaLocation="urn:dvb:metadata:servicediscovery:2019 dvbi_v1.0.xsd">

and the node/express code being used is

console.log(xmllint.validateXML({
	xml: fs.readFileSync(path.join('sample','ASTRA_19_2_E.xml')).toString(),
	schema: [fs.readFileSync(path.join('schema','dvbi_v1.0.xsd')).toString(), 
			 fs.readFileSync(path.join('schema','tva_metadata_3-1.xsd')).toString(), 
			 fs.readFileSync(path.join('schema','tva_mpeg7.xsd')).toString(),
			 fs.readFileSync(path.join('schema','xml.xsd')).toString()]
}));

the "sample" files can be found in https://github.com/paulhiggs/dvb-sl-check/tree/master/sample
the "schema" files can be found in https://github.com/paulhiggs/dvb-sl-check/tree/master/schema

The XML document validates OK with XMLspy 2019

@paulhiggs
Copy link
Author

paulhiggs commented Jun 20, 2024

Here is the most simple example to reproduce the error

let recipe_xsd=`<?xml version="1.0" encoding="utf-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:r="http://www.namespace.org/recipe" xmlns:s="http://www.namespace.org/servings" targetNamespace="http://www.namespace.org/recipe" version="1.0" elementFormDefault="unqualified" attributeFormDefault="unqualified">
	<import namespace="http://www.namespace.org/servings" schemaLocation="serving.xsd"/>
	<element name="recipe" type="r:recipe"/>
	<complexType name="recipe">
		<sequence>
			<element name="servings" type="s:servingsType"/>
		</sequence>
	</complexType>
</schema>`;

let serving_xsd=`<?xml version="1.0" encoding="utf-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:rx="http://www.namespace.org/servings" targetNamespace="http://www.namespace.org/servings" elementFormDefault="unqualified" attributeFormDefault="unqualified" version="1.0">
	<element name="guests" type="rx:servingsType"/>
	<simpleType name="servingsType">
		<restriction base="unsignedInt">
			<minInclusive value="1"/>
			<maxInclusive value="16"/>
		</restriction>
	</simpleType>
</schema>`;

let recipe_xml=`<?xml version="1.0"?>
<r:recipe xmlns:r="http://www.namespace.org/recipe" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.namespace.org/recipe recipe.xsd">
  <servings>12</servings>
</r:recipe>`;

The XML document uses a recipe schema (recive_1) which in turn uses a datatype defined in a second schema (recipe_2).

with

let e3 = xmllint.validateXML({xml:recipe_xml, schema: [recipe_xsd, serving_xsd ]});
console.dir(e3);

we get the output

{
  errors: [
    "file_0.xml:2: element recipe2: Schemas validity error : Element '{http://www.namespace.org/recipe}recipe2': No matching global declaration available for the validation root."
  ]
}

swapping the order of elements in the list of shemas to schema: [recipe2_xsd, recipe1_xsd ] gives

{
  errors: [
    "file_1.xsd:7: element element: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}element', attribute 'type': References from this schema to components in the namespace 'http://www.namespace.org/servings' are not allowed, since not indicated by an import statement."
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant