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

Schema Import: Search in relation to the path of the importing XSD file #11

Closed
bargru opened this issue Sep 25, 2019 · 3 comments · Fixed by #13
Closed

Schema Import: Search in relation to the path of the importing XSD file #11

bargru opened this issue Sep 25, 2019 · 3 comments · Fixed by #13

Comments

@bargru
Copy link
Contributor

bargru commented Sep 25, 2019

Hello,

I have problems with including an xsd file via an import.

My main XSD contains the following import:
<xs:import schemaLocation="dependency/second.xsd" namespace="second"/>

The import points to an XSD file located in a subfolder ("dependency") of the folder with the main XSD.

📁resources
|L 📁dependency
|  L second.xsd
L main.xsd

Other parsers (for example JAXB) can find and process the other imported second file without problems.

With XsdParser I get the following error when reading my main.xsd:

Sep. 25, 2019 7:41:39 AFTER. org.xmlet.xsdparser.core.XsdParser parseFile
SEVERE: Exception while parsing.
java.io.FileNotFoundException
	at org.xmlet.xsdparser.core.XsdParser.parseFile(XsdParser.java:77)
	at org.xmlet.xsdparser.core.XsdParser.parse(XsdParser.java:58)
	at org.xmlet.xsdparser.core.XsdParser.<init>(XsdParser.java:35)
	at Main.main(Main.java:17)

Exception in thread "main" java.util.NoSuchElementException: No value present
	at java.base/java.util.Optional.get(Optional.java:148)
	at org.xmlet.xsdparser.core.XsdParserCore.lambda$null$12(XsdParserCore.java:177)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
	at org.xmlet.xsdparser.core.XsdParserCore.lambda$resolveInnerRefs$17(XsdParserCore.java:174)
	at java.base/java.util.HashMap$KeySet.forEach(HashMap.java:928)
	at org.xmlet.xsdparser.core.XsdParserCore.resolveInnerRefs(XsdParserCore.java:164)
	at org.xmlet.xsdparser.core.XsdParserCore.resolveRefs(XsdParserCore.java:91)
	at org.xmlet.xsdparser.core.XsdParser.parse(XsdParser.java:62)
	at org.xmlet.xsdparser.core.XsdParser.<init>(XsdParser.java:35)
	at Main.main(Main.java:17)

When I remove the import, parsing works without problems. In the test to the namespaces I have seen that the path is given in relation to the project root. However, it cannot be expected that such path specifications are made in a "normal" XSD. An imported XSD file should (in my opinion) always be searched in relation to the importing XSD file.

By the way, thank you very much for this library! It saves me a lot of work.

@lcduarte
Copy link
Member

lcduarte commented Sep 28, 2019

Hello,

Thanks for the issue! I fixed it and performed a new release, 1.0.21, try it out and check if it works as you would expect and if so close this issue.

You are welcome, I've made this library as part of my thesis but I'm happy to know other people can use it as well :)

@bargru
Copy link
Contributor Author

bargru commented Oct 1, 2019

Many thanks for the quick fix!

Basically the parser now finds the imported schema. But there is a problem under Windows with the filepath. I fixed that in pull request #13. Problem was the search for slashes. The parentFile path had backslashes under Windows.
filePath = parentFile.substring(0, parentFile.lastIndexOf('/') + 1).concat(filePath);

I have fixed the problem by replacing all backslashes in the paths with normal slashes.
this.currentFile = filePath.replace("\\", "/");

@lcduarte
Copy link
Member

lcduarte commented Oct 1, 2019

Thanks for the input and the fix!

I included the fix and performed a new release, 1.0.23.

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

Successfully merging a pull request may close this issue.

2 participants