Reputation: 139
I´m trying to get all restrictions (minOccurs, maxOccurs, totalDigits, maxLength etc.) for elements, simpleTypes and complexTypes in an XML schema file. Since these restrictions are in child elements, it should be possible to select these restriction elements per xsd:element, xsd:simpleType and xsd:complexType, along with the value of the attribute "name". I can then loop through the result set element-by-element and fill a table with the restrictions for each element.
Unfortunately, I´m not able to build such an XPath expression. Maybe it isn´t even possible? This is what i have so far:
//*[xsd:element[@name] or xsd:simpleType[@name] or xsd:complexType[@name]]//xsd:restriction/descendant::*
This gets me the restrictions, like minOccurs etc., but I need to have the parent elements with their @name-value.
Upvotes: 0
Views: 1197
Reputation: 163549
Firstly, processing of raw schema documents at the XML level is difficult unless you know that the schema author is using the language in a particular way. There are simply too many ways of writing the same thing (for example, using model groups, attribute groups, xs:include, named types versus anonymous types, etc). You can avoid this problem by using a schema API to access the compiled schema, or by using Saxon's SCM which is an XML representation of the compiled schema - this eliminates the surface syntax variations and gives you access to the underlying schema component model, in an XML representation.
Secondly, you say you want "to fill a table" with the result. That is, the result you want is more complex than a simple string, number, or node-set. You are therefore outside the domain of XPath and into XQuery or XSLT - you want to construct a structured result.
Upvotes: 2