Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Failed to load external entity #420

Closed
happypennygames opened this issue Jun 13, 2021 · 6 comments
Closed

Failed to load external entity #420

happypennygames opened this issue Jun 13, 2021 · 6 comments
Labels

Comments

@happypennygames
Copy link

happypennygames commented Jun 13, 2021

I am attempting to perform local validation of a musicxml file exported using musescore (uncompressed xml). I'm using xmllint.js (https://github.com/kripken/xml.js/blob/master/xmllint.js) on a simulated client side using a python server. The validation pipeline works great with other xsd/xml pairs, but I get this error when I substitute musicxml.xsd for the schema (has nothing to do with the xml file itself).

warning: failed to load external entity "http://www.musicxml.org/xsd/xlink.xsd"
file_0.xsd:26: element import: Schemas parser warning : Element '{http://www.w3.org/2001/XMLSchema}import': Failed to locate a schema at location 'http://www.musicxml.org/xsd/xml.xsd'. Skipping the import.
warning: failed to load external entity "http://www.musicxml.org/xsd/xlink.xsd"
file_0.xsd:27: element import: Schemas parser warning : Element '{http://www.w3.org/2001/XMLSchema}import': Failed to locate a schema at location 'http://www.musicxml.org/xsd/xlink.xsd'. Skipping the import.
file_0.xsd:2248: element attribute: Schemas parser error : attribute use (unknown), attribute 'ref': The QName value '{http://www.w3.org/XML/1998/namespace}lang' does not resolve to a(n) attribute declaration.

I copied the full zip of all the files into the same place as the musicxml.xsd fiile.

The instructions in musicxml.xsd reference the catalog.xml file, but I do not reference it (I'm not sure how), so i don't know if that's the problem. I'm also ok with manually pasting all the other xsd files into the musicxml.xsd file if there was way to do that.

Modifying the musicxml.xsd file such that the schema location is just the file name, and running:

xmllint --schema musicxml.xsd t1.musicxml --noout --nonet

actually does validate at the command line in a linux terminal, which implies the fault is in some interaction of the import statement with xmllint.js at this point. Feel free to close the issue if no suggestions given this update.

@mdgood
Copy link

mdgood commented Jun 15, 2021

@happypennygames This page has instructions for using XML catalogs with lxml in Python. It sounds like this should work for your situation and is better than modifying the MusicXML schema files:

https://lxml.de/resolvers.html

Please let us know if this works for you.

@happypennygames
Copy link
Author

Thanks for posting! I did look at it as soon as you replied- unfortunately, couldn't make out how to use it. I will try for a deeper look this weekend and let you know my specific questions.

@happypennygames
Copy link
Author

The long and short of it- totally failed going that direction. But that's ok, I just kept pushing forward, and I appreciated the pointer. If you want to try out the application (free, no ads), you can upload simple uncompressed musicxml files (e.g. up to 8th notes) and try real time feedback with a keyboard- thanks again! https://play.google.com/store/apps/details?id=com.happypennygames.aimusic.sightreader

@apacha
Copy link

apacha commented Jan 12, 2022

Hi,
I've stumbled upon this problem too after upgrading to MusicXML Schema 4.0 DTD and I don't really see how the mentioned catalogues could solve the issue. I'm executing this very simple code, just trying to parse the schema:

from lxml import etree

schema_file_name: str = 'utils/data_files/musicxml.xsd'
schema = etree.XMLSchema(file=schema_file_name)

and I already get the following error:

Traceback (most recent call last):
  File "/Users/alex/musicxml_validation.py", line 5, in <module>
    schema = etree.XMLSchema(file=schema_file_name)
  File "src/lxml/xmlschema.pxi", line 88, in lxml.etree.XMLSchema.__init__
lxml.etree.XMLSchemaParseError: attribute use (unknown), attribute 'ref': The QName value '{http://www.w3.org/XML/1998/namespace}lang' does not resolve to a(n) attribute declaration., line 2247

which makes me question whether the schema can be used like that (by lxml) at all. For parsing the schema, there is no option for any catalog-resolver or the like.

Can you shed some light on this?

@mdgood
Copy link

mdgood commented Feb 2, 2022

@apacha Did you look at the linked article at https://lxml.de/resolvers.html? It explains the issue and provides links such as http://xmlsoft.org/catalog.html with information on how to set up catalogs for use with lxml.

@david-pace
Copy link

I just ran into the same issue when importing the MusicXML 4.0 XSD using the Eclipse Modeling Framework (EMF). If you're interested in some background information, you can read my blog post.

The error messages indicate that the schema locations of the following XSD imports (lines 26 and 27 of musicxml.xsd in the current 4.0 release) can not be resolved:

<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.musicxml.org/xsd/xml.xsd"/>
<xs:import namespace="http://www.w3.org/1999/xlink" schemaLocation="http://www.musicxml.org/xsd/xlink.xsd"/>

When browsing the URLs directly in a browser the XSDs are reachable, but there is a HTTP -> HTTPS redirection (e.g. from http://www.musicxml.org/xsd/xml.xsd to https://www.musicxml.org/xsd/xml.xsd); also my browser (Firefox) indicates that the connection is not safe for some reason. Probably the HTTPS redirection, the SSL certificate or both cause problems while resolving the XSD imports.

My solution was to replace the URLs with the following ones:

https://www.musicxml.com/xsd/xml.xsd
https://www.musicxml.com/xsd/xlink.xsd

With those schema locations the MusicXML XSD could be loaded without any problems. Consequently one solution could be to use https:// URLs in future versions.

@w3c w3c locked and limited conversation to collaborators Feb 15, 2022
@mdgood mdgood converted this issue into discussion #445 Feb 15, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

4 participants