albanm / node-libxml-xsd

XSD validation for node.js using libxml.
70 stars 28 forks source link

xsd with circular references is it supported? #21

Closed perseus086 closed 7 years ago

perseus086 commented 7 years ago

I added a xsd and then used the parseFile method but I am getting this error Error: Invalid XSD schema at Error (native).

The xsd has circular references, for instance:

FILE 1: <xs:include schemaLocation="./path/file2.xsd"/> ===> It asks for file 2. That's OK

FILE 2: <xs:include schemaLocation="file2.xsd"/> <xs:include schemaLocation="file3.xsd"/> ===>It asks for file 2. That's Wrong because it is asking for itself. Asking for file 3 OK

FILE 3: <xs:include schemaLocation="file2.xsd"/> ===>It asks for file 2. that was already called so that is wrong

If I remove the "circular references" the app works fine but my problem is that removing that is a manual process and schemas change periodically and contains lots of files.

Is there a way to fix this problem? Is it a normal problem or I am doing something wrong?

albanm commented 7 years ago

You can ttry validating using xmllint, something like this :

xmllint --noout --schema XSD_FILE XML_FILE

If you get the same error, then the problem is not with this nodejs wrapper but with the underlying lib.

perseus086 commented 7 years ago

@albanm Effectively I tried with xmllint and I got multiple errors like this one:

xmllint --noout --schema abcde.xsd abcd-sc.xsd:5: element include: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}include': The schema document 'abcd-sc.xsd' cannot include itself.. WXS schema abcd.xsd failed to compile

I removed all the inclusions to itself. But I continue having the issue: Invalid XSD schema. This is caused by the circular references, that is a file that is already called is called again by another file because when I remove all that it works fine.

Do you know if calling to itself is acceptable on the standard of XSDs? because I read the standard and nothing says you cannot do this.

Maybe it is just not implemented by libxml

albanm commented 7 years ago

I have no idea unfortunately. As your problem is with the underlying lib, not specifically with this wrapper, I will close this issue.