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 David Bonnecaze <DB...@Cornell-Mayo.com> on 2001/08/15 16:32:07 UTC

Validation and Element insertion question

My program reads in an xml data file that is validated against a DTD file.
I am trying to migrate to xerces 1.5.1 to fix some of the performance and
memory leak problems my program is experiencing.  I am having 2 issues with
the migration.

1.  Validate an Element before adding it to the DOM.

In Xerces version 1.1 I did the following:

bool CMA_XPATHWRAPPER::isValidElem(DOM_Node node) const
{

  // establish elemID for the node to be validated
  unsigned int elemID =
validator->findElemId(node.getNodeName().rawBuffer()) ;
  if ( elemID == XMLElementDecl::fgInvalidElemId )
    return false ;

  // bulid elemID list for all children of the Node
  DOM_NodeList childNodeList = node.getChildNodes() ;
  unsigned int* childIdx = new unsigned int[childNodeList.getLength()] ;
  memset(childIdx,0x00,(childNodeList.getLength()*sizeof(int))) ;

  // establish elemIDs and load them in the childIdx for all the children of
the node
  unsigned int count = 0 ;
  for (int i=0; i < childNodeList.getLength() ; i++)
  {
    unsigned int id =
validator->findElemId(childNodeList.item(i).getNodeName().rawBuffer()) ;
    if (id != XMLElementDecl::fgInvalidElemId)
      childIdx[count++] = id ;
  }

  // validate the elem

  if (validator->checkContent(elemID,childIdx,count) ==
XMLValidator::Success) 
    return true ;

  return false ;
}

With the use of the DTDGrammer and the changes to the checkContent method I
am not sure how to perform this action now.  And am wondering if there is an
easier way to accomplish this.  It would seem that there should be way so as
not to drill so deeply into the Xerces code.

2.  Determine where to slot a child element in an element.

Because a DTD can define a sequence for a list of elements it would seem
that a means to determine where an element should be slotted should exist.
Currently, in Xerces 1.1, I had modified the content objects, mixedcontent,
etc., to treat my class as a friend so that I could walk the child node
enumeration list of the XMLElemDecl so I could determine where a new element
should be inserted.

Example:

DTD

<!ELEMENT parent ( childelem4?, childelem2? childelem3?)>

First childelem2 is appended to parent.  Then childelem4 is passed and it
needs to be appended to parent.  How will I know that childelem4 comes
before childelem2.

This does not seem to be the correct approach to me.  Does an easier method
exist.  I application is such that I would not know what the element order
is except for the information the DTD provides.



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