You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Elisha Berns <e....@computer.org> on 2005/03/16 20:29:41 UTC
Advanced novice question about PSVI
To All,
I have a question whether I can use PSVI for an algorithm I have in
mind...
My goal is to take the content model from XSD schema documents and
transform it into an ordered graph/tree that can be used to serialize
application data in the order corresponding to the content model. If
the schema's content model changes then the algorithm automatically
rebuilds the graph/tree to for serialization.
I understand what to do in general if I already have an in memory
graph/tree structure of the schema content model: rely on the ordering
of the graph/tree nodes in a depth first search to write out application
data that corresponds to each node in the graph/tree. I may need to do
a topological sort first on the graph, but that is really just a detail.
What I don't understand is how to transform an XSD schema document, with
all its verbose structures, into a simple directed acyclic graph (or
tree) of element identifiers that mimics the content model. Basically I
would build something that looks like an instance document and not an
XSD document, or I would build an in memory graph of the same purpose.
Can the PSVI interfaces/classes be used to just parse an XSD schema
without having to parse an instance document? And if so, somehow, can
the PSVI classes then be used to create a simple mirror of the content
model?
I have a feeling that I may need to do a two step process here: use
XSLT to transform the XSD to a simple model, then build the in memory
representation from the simplified model.
If someone can opine here I will appreciate it greatly.
Yours,
Elisha Berns
e.berns@computer.org
tel. (310) 556 - 8332
fax (310) 556 - 2839
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
RE: Advanced novice question about PSVI
Posted by da...@us.ibm.com.
> Well,
>
> I've been digging around a lot to understand what Xerces does and does
> not allow and there seems to be some problem with Xerces here. If I
> follow your tip and use the ContentSpecNode I end up in a dead end. I
> can get the ContentSpec, but it doesn't do me much good, all that it
> seems to allow is retrieving a "formatted content model", sometimes:
You might want to consider using the XSModel classes. The files are
located in src/xercesc/framework/psvi, and you can get use a PSVIHandler
to get information while parsing an instance document. You can also load
a grammar into a parser, and ask it for the XSModel for that grammar.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
RE: Advanced novice question about PSVI
Posted by Elisha Berns <e....@computer.org>.
Well,
I've been digging around a lot to understand what Xerces does and does
not allow and there seems to be some problem with Xerces here. If I
follow your tip and use the ContentSpecNode I end up in a dead end. I
can get the ContentSpec, but it doesn't do me much good, all that it
seems to allow is retrieving a "formatted content model", sometimes:
ContentSpecNode* pSpecNode = element.getContentSpec();
if ( pSpecNode )
{
XMLElementDecl* pElemDecl = pSpecNode->getElementDecl();
if ( pElemDecl )
{
XMLCh const* szModel =
pElemDecl->getFormattedContentModel();
}
}
Alternatively I can get the content model another way by doing this:
XMLContentModel* pModel = element.getContentModel();
Where the 'element' came from SchemaGrammar::getElemEnumerator().
But casting pModel to something like SimpleContentModel doesn't help
because the class ContentLeafNameTypeVector isn't exported from Xerces
so it generates a link error (even though XMLContentModel let's you
access it with an API):
void XsdGraph::GetContentVector(SimpleContentModel* pModel)
{
ContentLeafNameTypeVector* pVector =
pModel->getContentLeafNameTypeVector();
if ( pVector )
{
for ( unsigned int i = 0; i < pVector->getLeafCount(); i++ )
{
wcout <<
L"Name: " << pVector->getLeafNameAt(i)->getLocalPart()
<<
L" Type: " << pVector->getLeafTypeAt(i) << endl;
}
}
}
So you have apparently two designs here: one internal to the library and
one for clients of the library, or so it seems.
Anyways, I'm back at my original question: what's the way to get the
list of parent/child relationships in a schema (elements and their
sub-elements, types and their sub-types) in order to build something
like a dependency graph from the schema elements?
Yours,
Elisha Berns
> -----Original Message-----
> From: Gareth Reakes [mailto:gareth@parthenoncomputing.com]
> Sent: Friday, March 18, 2005 6:51 AM
> To: xerces-c-dev@xml.apache.org
> Subject: Re: Advanced novice question about PSVI
>
> Hey,
>
> >
> > There is a general mapping between schema types and application
classes.
> > Think of it as a way to save an application as a graph provided you
know
> > what the node definitions are ahead of time.
> >
>
> Good, that will help a lot.
>
>
> >
> > Well I see this in the PSVI classes and I have started development
on
> > it, but here is really where my questions are: How do you get all
the
> > sub elements of complexContent or other composite types?
>
> Take a look at the Grammar class. This will lead you on to things like
> SchemaElementDecl which has getContentSpec. That method will give you
a
> content model.
>
>
> Regards,
>
> Gareth
>
> --
> Gareth Reakes, Managing Director Parthenon Computing
> +44-1865-811184 http://www.parthcomp.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Advanced novice question about PSVI
Posted by Gareth Reakes <ga...@parthenoncomputing.com>.
Hey,
>
> There is a general mapping between schema types and application classes.
> Think of it as a way to save an application as a graph provided you know
> what the node definitions are ahead of time.
>
Good, that will help a lot.
>
> Well I see this in the PSVI classes and I have started development on
> it, but here is really where my questions are: How do you get all the
> sub elements of complexContent or other composite types?
Take a look at the Grammar class. This will lead you on to things like
SchemaElementDecl which has getContentSpec. That method will give you a
content model.
Regards,
Gareth
--
Gareth Reakes, Managing Director Parthenon Computing
+44-1865-811184 http://www.parthcomp.com
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
RE: Advanced novice question about PSVI
Posted by Elisha Berns <e....@computer.org>.
Thanks for the reply,
Comments below...
> -----Original Message-----
> From: Gareth Reakes [mailto:gareth@parthenoncomputing.com]
> Sent: Thursday, March 17, 2005 12:58 AM
> To: xerces-c-dev@xml.apache.org
> Subject: Re: Advanced novice question about PSVI
>
> Hi,
>
> >
> > I have a question whether I can use PSVI for an algorithm I have in
> > mind...
> >
> > My goal is to take the content model from XSD schema documents and
> > transform it into an ordered graph/tree that can be used to
serialize
> > application data in the order corresponding to the content model.
If
> > the schema's content model changes then the algorithm automatically
> > rebuilds the graph/tree to for serialization.
>
> Is there any mapping between the application and the schema? How will
> you decide on how to map to things like recursive definitions and
choices?
There is a general mapping between schema types and application classes.
Think of it as a way to save an application as a graph provided you know
what the node definitions are ahead of time.
>
> > What I don't understand is how to transform an XSD schema document,
with
> > all its verbose structures, into a simple directed acyclic graph (or
> > tree) of element identifiers that mimics the content model.
Basically I
> > would build something that looks like an instance document and not
an
> > XSD document, or I would build an in memory graph of the same
purpose.
>
> You can get hold of the grammar after you cache it (and in other
ways).
> That gives you a set of classes that define the content model.
Well I see this in the PSVI classes and I have started development on
it, but here is really where my questions are: How do you get all the
sub elements of complexContent or other composite types?
>
> > And if so, somehow, can
> > the PSVI classes then be used to create a simple mirror of the
content
> > model?
>
> XML Schema and simple in the same sentence :) You can define very
> complex content models and the resulting grammar would be hard to map
> onto application data without prior knowledge.
>
Of course, as stated above your correct.
>
> > I have a feeling that I may need to do a two step process here: use
> > XSLT to transform the XSD to a simple model, then build the in
memory
> > representation from the simplified model.
>
> Can you expand on what you mean by simple?
>
>
> Gareth
>
> --
> Gareth Reakes, Managing Director Parthenon Computing
> +44-1865-811184 http://www.parthcomp.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Advanced novice question about PSVI
Posted by Gareth Reakes <ga...@parthenoncomputing.com>.
Hi,
>
> I have a question whether I can use PSVI for an algorithm I have in
> mind...
>
> My goal is to take the content model from XSD schema documents and
> transform it into an ordered graph/tree that can be used to serialize
> application data in the order corresponding to the content model. If
> the schema's content model changes then the algorithm automatically
> rebuilds the graph/tree to for serialization.
Is there any mapping between the application and the schema? How will
you decide on how to map to things like recursive definitions and choices?
> What I don't understand is how to transform an XSD schema document, with
> all its verbose structures, into a simple directed acyclic graph (or
> tree) of element identifiers that mimics the content model. Basically I
> would build something that looks like an instance document and not an
> XSD document, or I would build an in memory graph of the same purpose.
You can get hold of the grammar after you cache it (and in other ways).
That gives you a set of classes that define the content model.
> And if so, somehow, can
> the PSVI classes then be used to create a simple mirror of the content
> model?
XML Schema and simple in the same sentence :) You can define very
complex content models and the resulting grammar would be hard to map
onto application data without prior knowledge.
> I have a feeling that I may need to do a two step process here: use
> XSLT to transform the XSD to a simple model, then build the in memory
> representation from the simplified model.
Can you expand on what you mean by simple?
Gareth
--
Gareth Reakes, Managing Director Parthenon Computing
+44-1865-811184 http://www.parthcomp.com
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org