[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]
Re: [xml-dev] Seek your suggestions on how to determine if an XMLSchema supports the structures denoted by XPath expressions
- From: "Liam R. E. Quin" <liam@fromoldbooks.org>
- To: Roger L Costello <costello@mitre.org>, "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
- Date: Fri, 05 Feb 2021 02:52:43 -0500
On Thu, 2021-02-04 at 20:36 +0000, Roger L Costello wrote:
>
> I want to automate things: for each XPath-ish expression, determine
> if my XML Schema supports the structure denoted by the expression.
This is an interesting question, and has clear application for example
to XSLT match expressions.
One brute force way would be to construct a sample document for each
XPath expression, but apart from efficiency questions, i'm not sure
it's any easier than interpreting the schema.
We might say, given a path such as /a/b/c and an XML Schema S that
defines an "a" element of type T(a), can this contain an element of
name b, and if so is there such an element that can contain a child
called c.
This is somewhat complicated by substitution groups, but not
intractably, since schema validators exist.
Where the path is not rooted, it might be easier to work right to left,
as some XPath implementations do, so that for d/e/f you first look for
a definition of f and then ask if there's an e that can contain it, and
so on.
I can see adopting either of these approaches in XSLT.
It gets harder if there are additional rules, such as uniqueness
constraints or Schematron rules to satisfy. But i think i'd probably go
for the schema interpreter rather than the sample instance approach.
You could also write an optimizer. For example, if div can contain div,
then body/div/div/div/p can be rewritten as body/div/p for the purpose
of the test. That might help reduce the scale of the problem.
Liam
--
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations: http://www.fromoldbooks.org
[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]