Open mithro opened 5 years ago
I don't think this would work. Even the non-requirement of order on the attributes will make the resulting regular expression explode combinatorially. Think of an element with 6 required attributes:
<element (attr1="([\w]*)" attr2="([\w]*)" attr3="([\w]*)" attr4="([\w]*)" attr5="([\w]*)" attr6="([\w]*)")
|(attr1="([\w]*)" attr2="([\w]*)" attr3="([\w]*)" attr4="([\w]*)" attr6="([\w]*)" attr5="([\w]*)"
| [718 more permutations...] >
Use an or and a match X times. Something like....
<element (attr1="([\w]*)"|attr2="([\w]*)"|attr3="([\w]*)")*>
Yes, but then we won't be checking if all required attributes are present. State machines are really bad at handling independent inputs.
@duck2 - That can be done after the tag has been parsed?
Need to think more. Maybe we could make something like an opinionated SAX parser out of this, output of which can be fed to the general purpose validators.
@duck2 Notice how I separated some final validation from the parsing in the example here -> https://github.com/duck2/uxsdcxx/issues/1#issuecomment-506573231
pugixml is a generic XML parser. However, now we are generating a parser, we should see if we can do better by creating a parser that only parses files in the exact given XML formats. Using something like Google's re2 would be a good option for that.