Hi Michael,

At 21.18 19/12/2005 +0100, Michael Hagedorn wrote:
Hello Alberto,

Alberto Massari wrote:
>
> You could use parser->getGrammar("urn:my:namespace"), but you really
> need the GrammarResolver in order to get the uriId for a given
> namespace. You have to downcast the pointer to DOMBuilderImpl.
>
DOMBuilderImpl inherits protected getGrammarResolver() from baseclass
AbstractDOMParser. So I see no way to acces it. Neither by downcast.

Yes, you are right... as a partial excuse, I usually derive a class from XercesDOMParser when I need to access the Grammar; if you don't really need the W3C interface you can do the same.


>> How do I get XMLElementDecl from SchemaGrammar?
>
> The code I wrote assumes that "title" is a global element; if it is a
> local element you may want to drill down from the corresponding global
> element.
> So, if you look for the "title" of a "book" inside the global "books"
> you will have to search
>
>
SchemaElementDecl*
>books=(SchemaElementDecl*)g->getElemDecl(r->getStringPool()->getId( "urn:my:namespace"),
> "books", 0, Grammar::TOP_LEVEL_SCOPE);
>
>
SchemaElementDecl*
>book=(SchemaElementDecl*)g->getElemDecl(r->getStringPool()->getId(" urn:my:namespace"),
> "book", 0, books->getComplexTypeInfo()->getScopeDefined());
>
>
SchemaElementDecl*
>title=(SchemaElementDecl*)g->getElemDecl(r->getStringPool()->getId( "urn:my:namespace"),
> "title", 0, book->getComplexTypeInfo()->getScopeDefined());
>
Yes, this should work. But I don't know the structure of my XML. So using
this approach means traversing through getParentNode(), right?

My hope is PSV can help. Isn't it?

DOMPSVITypeInfo *typeInfo =
(DOMPSVITypeInfo*)domNode->getInterface(XMLUni::fgXercescInterfacePSVITypeInfo);
const XMLCh *typeName =
typeInfo->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Name);
const XMLCh *typeURI =
typeInfo->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Namespace);

So in general you want to read the annotation of any validated element, without any previous knowledge of the schema used? In this case you should build the list title->book->books by navigating the DOM tree, then navigate downwards as I showed. Or navigate to the parent, ask for the PSVI information, check it is not an anonymous type, retrieve the global complex type with the name and ask for the element with that enclosing scope. If the parent has an anonymous type, go to the parent and try again.

Alberto


Reply via email to