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 Lyman Neuschaefer <ln...@tecomac.com> on 2001/09/06 20:01:59 UTC

Need *effective* access to SchemaGrammar interface after parsing a document

Greetings,

I'm working on the following problem.  I'd like to parse an XML document
and store its contents in a tree-like data structure of our company's own
design.  Part of that design involves storing attributes and textual content
within "simpleType" elements possibly as int, float, double, etc, as defined

by a constraining XML schema document.

My current approach is first to populate the data tree with elements and
attributes whose contents are purely character strings.  Then, traverse
this data tree and perform a lookup of the current element name or 
attribute name in the SchemaGrammar object which was built during the 
parsing operation. For example:


  // Establish a SAX parser which supports namespaces and performs
  // schema validation.  Then parse an XML document

    parser.parse(xmlDocument);


  // Get the SchemaGrammar object which was populated during the parse

    SchemaGrammar* grammar = static_cast<SchemaGrammar*>
      (parser.getValidator()->getGrammar());


  // Get the data structure populated during the parse which contains
  // an in-memory representation of xmlDocument

    ProprietaryXMLTree* xmlTree = parser.getXMLTree();


  // Traverse the xmlTree, converting the contents of "simpleType" 
  // elements and the values of attributes from character strings to
primitive 
  // data types, as indicated by the constraining XML schema document.

  // This can be done recursively.  Below is shown how this operation would
  // be applied for a given element named elementName.

  int targetNSID = /* Somehow obtain the URI ID associated with the target 
	               * namespace where all elements and attributes within 
                           * xmlDocument are contained */

  SchemaElementDecl* schemaDecl = static_cast<SchemaElementDecl*>
     (grammar->getElemDecl( targetNSID, XMLString::transcode(elementName),
                                           NULL, Grammar::TOP_LEVEL_SCOPE);

  // Enquire about the content model of the current element from schemaDecl
  // and perform the necessary operations for simpleTypes used within this
element.


This lengthly preamble is needed to pose the following question.  How do I
obtain the value for targetNSID above? SchemaGrammar supplies method
XMLCh* getTargetNamespace(), but what I need is a method like
int getTargetNamespaceID().  In fact, I have modified SchemaGrammar
to supply just such a method, where the integer value returned is 
equivalent to that of the TraverseSchema data member fTargetNSURI.

I'd greatly appreciate anyone who can provide me a less odious solution
than having to modify the xerces source code to accomplish my 
objective.

Thanks,


Lyman Neuschaefer
Tecomac, Inc
lneuschaefer@tecomac.com


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org