Add XML Schema Validation
Breaking #40 into smaller chunks for Hacktoberfest. We'd really like to start adding schema validation in addition to syntax validation. XML seems like a good one to start with. We'd like to support validation against DTD as well as XSD.
@kehoecj Looking into this and see what’s possible.
@kehoecj Can you please assign it to me? Just so I don't lose track :)
@kehoecj Do you have a specific file naming convention for the schema and syntax validators to differentiate them? Or should I create a new directory of schema validators? Just getting some information to keep it maintainable for everyone. Thanks 😄
Schema validation should be in the validator package and inside the xml.go validator
@kehoecj Sorry if I'm bombarding you, but I need some guidance. If we want to enable validation against XSD or DTD, we would also need to provide a way for the user to specify a path to the schema file, right? But this would end up in a new flag? Or am I thinking the wrong way?
@kehoecj Just tagging you so that you can give me a little hint as to how I might do it. Thanks :)
@kehoecj Sorry if I'm bombarding you, but I need some guidance. If we want to enable validation against XSD or DTD, we would also need to provide a way for the user to specify a path to the schema file, right? But this would end up in a new flag? Or am I thinking the wrong way?
You're on the right track. With XML the XSD/DTD URL or local path can be declared in the XML. We may want to just start with that as the MVP/POC. It's likely one of the go XML libraries already does some of this. Here's what I'm thinking:
- If there is not XSD/DTD attribute declared in the file just check the syntax
- If there is is an XSD/DTD declared AND the file can be obtained then validate schema and syntax. Prioritize outputting the syntax error first then schema issue.
- Add a flag to just check the syntax, i.e. the current behavior. Something like
--syntax-only
@timwehrle Does that help?
@kehoecj Ah, yes. Thank you. I was probably overthinking it and missed the simpler solution.
@kehoecj So basically my code can retrieve the XSD/DTD schema file (had to implement a custom function using regex because the go xml libraries don't provide a way). But the problem is that I can't read the file because I would need to locate it first. But I can't manage to use the already implemented FileFinder that is in the project because it would resolve in import cycle errors. How would you proceed from here? Should I implement a function myself? Thanks for helping out :)
@timwehrle Interested in taking another look at this?
@kehoecj Hmm, I don't know if I have the time for it.