0

I have an xsd file that includes a bunch of repeating groups and I want to obtain a list of their paths. (There's mostly non-repeating groups in here; I don't care about these.)

I'm thinking that I can navigate through some sort of tree representation of the schema, and check if a node is repeating. If yes, I'll write its xpath to a file. If not, I'll skip over it.

I know I can generate an scm file using Saxon and this answer How can I find all elements in an XML Schema whose value is specified as a QName? but I'm only partially sure that this is the way to go.

Are there any known ways to do this?

Community
  • 1
  • 1
asdvbnm
  • 53
  • 7

1 Answers1

0

I'm not sure exactly what you mean by a "repeating group" (it reminds me of something in COBOL...) but I don't think that's really the point.

In general I advise against trying to process source schema documents using XPath and XSLT because getting it right is too difficult - there are too many ways to write equivalent schemas. There are various alternatives: with Saxon you can use the SCM file, or use the saxon:schema() extension function to process the compiled schema component model; or with Xerces there is a Java API to do this.

On reservation is your term "repeating group". By group, do you mean an xs:group element with a name attribute (XSD calls this a "model group definition"), or with a ref attribute (a "model group reference"), or do you mean a "group definition component" which is a generic term for model group definitions and attribute group definitions, or do you mean a "substitution group", or do you mean a "model group", which corresponds to an xs:choice, xs:sequence, or xs:all element? XSD terminology can be terribly confusing - and without knowing EXACTLY what you are looking for, it's hard to advise.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Thanks for the response. I should have been clearer; I'm referring to xs:element. They all have name and type attributes (with complexTypes defined in the schema). Some of them have minOccurs and maxOccurs. I need to create a list of the paths for those elements with min/maxOccurs. – asdvbnm Sep 09 '16 at 17:35
  • What output do you want if the list of paths is infinite, e.g. /doc/section/section/section/section/... ? – Michael Kay Sep 10 '16 at 08:27
  • I know that it will never be in this particular use case. – asdvbnm Sep 13 '16 at 20:11
  • I expect you know a lot of things about the requirement that you haven't told us. You need to write a specification. – Michael Kay Sep 14 '16 at 06:42