You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Martin Uhrin <ma...@gmail.com> on 2011/11/16 00:14:04 UTC

Seeking help with extracting substitution group information from schema

Dear Xerces users/devs,

first of all: thanks for the great library and any help that you can
provide with my current predicament.

I'm trying to extract the substitution group from my schema for a
given element in my xml document.  I understand there might be a way
to do this by implementing a custom PSVIHandler, however I've taken a
slightly different route.  I instantiate a default GrammarPool and
pass it to my DOMParser which I then use to load my schema.  I then
parse my xml document and whenever I encounter an element that I need
the substitution group for I do something along the following lines:

GrammarPool->getXSModel()->getElementDeclaration(...)->getSubstitutionGroupAffiliation()->getName()

So question 1) Is this a reasonable way to accomplish this or should I
be using a different approach?

Question 2)

Currently, the way I match the element to the element declaration is
along the following lines:

XSModel->getElementDeclaration(element->getLocalName(),
element->getNamespaceURI())

this feels like it may not work in all cases.  How does Xerces match
each element to an element declaration when it is doing validation?  I
had a good look through the source but I couldn't see how this is
done.

Many thanks,
-Martin

Re: Seeking help with extracting substitution group information from schema

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Martin Uhrin <ma...@gmail.com> wrote on 11/15/2011 06:14:04 PM:

> first of all: thanks for the great library and any help that you can
> provide with my current predicament.
>
> I'm trying to extract the substitution group from my schema for a
> given element in my xml document.  I understand there might be a way
> to do this by implementing a custom PSVIHandler, however I've taken a
> slightly different route.  I instantiate a default GrammarPool and
> pass it to my DOMParser which I then use to load my schema.  I then
> parse my xml document and whenever I encounter an element that I need
> the substitution group for I do something along the following lines:
>
> GrammarPool->getXSModel()->getElementDeclaration
> (...)->getSubstitutionGroupAffiliation()->getName()
>
> So question 1) Is this a reasonable way to accomplish this or should I
> be using a different approach?

Computing an element's substitution group is more complex than that. An
element can block substitutions. You would need to check that too.

For convenience, we added the getSubstitutionGroup() method [1] to the Java
version of XSModel. Seems like that was never added to Xerces-C++.

> Question 2)
>
> Currently, the way I match the element to the element declaration is
> along the following lines:
>
> XSModel->getElementDeclaration(element->getLocalName(),
> element->getNamespaceURI())
>
> this feels like it may not work in all cases.  How does Xerces match
> each element to an element declaration when it is doing validation?  I
> had a good look through the source but I couldn't see how this is
> done.

Also more complex than that. It uses a state machine [2].

> Many thanks,
> -Martin

Thanks.

[1]
http://xerces.apache.org/xerces2-j/javadocs/xs/org/apache/xerces/xs/XSModel.html#getSubstitutionGroup%28org.apache.xerces.xs.XSElementDeclaration%29
[2]
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/validators/common/DFAContentModel.cpp?annotate=901107

Michael Glavassevich
XML Technologies and WAS Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org