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

XML Schema validation with lxml #425

Open
rwuthric opened this issue Mar 15, 2024 · 1 comment
Open

XML Schema validation with lxml #425

rwuthric opened this issue Mar 15, 2024 · 1 comment

Comments

@rwuthric
Copy link
Contributor

We are trying to setup an XML file validation process using the official MTConnect schema.
We use for this the python library lxml like so:

from lxml import etree

# Load xml file to validate
tree = etree.parse('mtc_file.xml')

# Load the MTConnect XML schema
with open('MTConnectDevices_2.3_1.0.xsd') as f:
    xmlschema_doc = etree.parse(f)
    xmlschema = etree.XMLSchema(xmlschema_doc)

# Validate the MTConnect XML device model file
if not tree.validate(schema):
    print('The XML device model file does not follow the MTConnect standart.')

We tried using the MTConnect schema MTConnectDevices_2.2.xsd, MTConnectDevices_2.3_1.0.xsd, MTConnectDevices_2.3.xsd and MTConnectDevices_2.3_1.0.xsd and they all ended up with errors when attempting to load them with xmlschema = etree.XMLSchema(xmlschema_doc).

For example for MTConnectDevices_2.2.xsd, lxml claims to find this error in the schema:

lxml.etree.XMLSchemaParseError: Element '{http://www.w3.org/2001/XMLSchema}any': The attribute 'notNamespace' is not allowed., line 7581

I was wondering if this is an issue of lxml or if something is indeed not 100% correct in MTConnectDevices_2.2.xsd.
Does anyone has experience with XML validation with other tools than lxml?

@wsobel
Copy link
Member

wsobel commented Mar 15, 2024 via email

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

No branches or pull requests

2 participants