config-file-validator icon indicating copy to clipboard operation
config-file-validator copied to clipboard

Add XML Schema Validation

Open kehoecj opened this issue 1 year ago • 11 comments

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 avatar Oct 03 '24 02:10 kehoecj

@kehoecj Looking into this and see what’s possible.

timwehrle avatar Oct 11 '24 09:10 timwehrle

@kehoecj Can you please assign it to me? Just so I don't lose track :)

timwehrle avatar Oct 11 '24 15:10 timwehrle

@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 😄

timwehrle avatar Oct 14 '24 16:10 timwehrle

Schema validation should be in the validator package and inside the xml.go validator

kehoecj avatar Oct 14 '24 16:10 kehoecj

@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?

timwehrle avatar Oct 14 '24 19:10 timwehrle

@kehoecj Just tagging you so that you can give me a little hint as to how I might do it. Thanks :)

timwehrle avatar Oct 23 '24 17:10 timwehrle

@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:

  1. If there is not XSD/DTD attribute declared in the file just check the syntax
  2. 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.
  3. Add a flag to just check the syntax, i.e. the current behavior. Something like --syntax-only

@timwehrle Does that help?

kehoecj avatar Oct 23 '24 17:10 kehoecj

@kehoecj Ah, yes. Thank you. I was probably overthinking it and missed the simpler solution.

timwehrle avatar Oct 23 '24 17:10 timwehrle

@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 avatar Oct 26 '24 09:10 timwehrle

@timwehrle Interested in taking another look at this?

kehoecj avatar Oct 07 '25 23:10 kehoecj

@kehoecj Hmm, I don't know if I have the time for it.

timwehrle avatar Oct 17 '25 08:10 timwehrle