Hi Frank,
At 05:23 PM 1/3/2006 -0800, Xiaofan Zhou wrote:
Hi All,
I got a few questions regarding schema paring in Xerces:
(1) I created a parser and load grammar like this:
SAX2XMLReader* pParser = XMLReaderFactory::createXMLReader();
pParser->loadGrammar(theSchema, Grammar::SchemaGrammarType);
Now can I start traversing the schema without calling the
parse(...) method on the pParser? I would like to create my own
representation of the schema, so I need to fully traverse the
schema starting from a root element.
(2) Also, in order to select a root element, Is there a way to get a
list of all global elements under a certain namespace if the schema
import schemas that have different target namespaces?
You can navigate the Grammar object that is returned by the
loadGrammar call (after casting it to be a SchemaGrammar*), and
iterate over all the defined elements using getElemEnumerator and
check the getEnclosingScope to be Grammar::TOP_LEVEL_SCOPE. In order
to navigate over different namespaces you should get the
corresponding Grammar object using pParser->getGrammar("namespace").
An alternative approach is to build an XSModel out of the pool of
Grammar objects, using this pseudo code:
#include <xercesc/internal/XMLGrammarPoolImpl.hpp>
...
XMLGrammarPoolImpl myPool;
SAX2XMLReader* pParser =
XMLReaderFactory::createXMLReader(XMLPlatformUtils::fgMemoryManager, &myPool);
pParser->loadGrammar(theSchema, Grammar::SchemaGrammarType, true);
XSModel* pModel=myPool.getXSModel();
XSNamedMap<XSObject>
*allGlobalElement=pModel->getComponentsByNamespace(ELEMENT_DECLARATION,
"urn:namespace");
...
(3) A specific question regarding import statement. If I have two
statements like this in a schema:
<xsd:import namespace="ns1" schemaLocation="schemaA.xsd">
<xsd:import namespace="ns2" schemaLocation="schemaB.xsd">
But schemaA.xsd refers to elements and types in schemaB, is
this supposed to work? I use Xerces-C 2.7 and I got type not found
error. If I switch the two import statements, then it works fine.
If schemaA.xsd contains a <xsd:import namespace="ns2"
schemaLocation="schemaB.xsd"> this is a bug. If it is missing, please
add it, as any imported schema must be a valid schema and you cannot
references definitions to a different namespace without first importing it.
Changing the order of the declaration works because schemaA.xsd will
find the schema already loaded in memory when it tries to locate
those definitions.
Hope this helps,
Alberto
I also notice that the same thing using include statement, that
is, the following won't work if schemaA.xsd refers something in schemaB.xsd:
<xsd:import namespace="ns1" schemaLocation="schemaA.xsd">
<xsd:include schemaLocation="schemaB.xsd">
But this will work:
<xsd:include schemaLocation="schemaB.xsd">
<xsd:import namespace="ns1" schemaLocation="schemaA.xsd">
But isn't it true that the import elements must appear as the
first children of the schema element?
Thanks much in advance.
Frank
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]