I was working on a project that has methods for 1) extracting all xpaths of elements that are present in the xml document itself (for example, a schema definition document) or 2) listing all possible xpaths that can be found in the XML document described by XSD.
If you are only interested in 1) the problem and my solution were described and answered (albeit in Scala) to Scala: what is the easiest way to get all leaf nodes and their paths in XML?
For 2) everything is much more complicated, although I actually used 1) as a starting point, and both: 1) ( XpathXmlEnumerator ) and 2) ( XpathXsdEnumerator ) have a common interface ( XpathEnumerator ), no matter what. Although 2) is much longer, I believe that ~ 500 VOCs are still a rather poor implementation, all the things considered (but probably could use more comments - please add them!). @michael-kay did a great job of describing many difficulties and describing a possible solution. Perhaps, unfortunately, I did not follow his advice on using software that understands the model of schema components, but I used scala.xml to try to simplify the work with xml nodes in general. However, I believe that I have overcome all the known difficulties of generating xpaths, since XSD has a high percentage of information / nodes, which is not necessary to generate XPath in documents described by XSD, so one can simply ignore such nodes.
The idea of ββfiltering becomes important in order to avoid counting nodes that appear everywhere, and in practice you are not interested, and perhaps also avoid recursion. However, recursion should be automatically detected by the implementation in clause 2), and further traversal of this xpath was excluded. For filters, the use of the custom class NodeFilters - see DdiCodebookSpec , for example, use.
You can see some tests that run in the project in the same directory as ShipOrderXsdSpec , which contains some quick-launch examples if you want to try it. Some of the other tests do not work quickly, and some of them have problems - this is the "pre-alpha" software!
Although the solutions are in Scala, I would be happy to create a Java shell (if necessary, it can work directly) and even publish it to Maven if anyone really wants to.