Hello Dave,

I have posted the code that calls the function below. First let me explain some. The code that calls the below function is written in C not C++. This is why the first parameter is a void pointer instead of a XalanParsedSource pointer. But I am sure that the parameters passed into the function are correct. The incomming array is actually a static char array, and the length is computed by sizeof( array ).

-----Explaination of parameters in below function. -----

void *parsed_source = Really a XalanParsedSource pointer. This is the same value as returned by a call to the XalanTransformer->parseSource() function.

NLETS_XML_ID *id = This points to a structure on the stack, no dynamic mem allocation.
#define XML_ID_LEN 40
typedef struct _NLETS_XML_ID_
{
char element[ XML_ID_LEN ];
char type[ 10 ];
} NLETS_XML_ID;


int IdentifyNletsDOM( void *parsed_source, NLETS_XML_ID *id, char *err_buf, int err_len )
{
/* First of all, clear out the ID structure */
memset( id, NULL, sizeof( NLETS_XML_ID ) );


  /* Convert the parsed source pointer */
  XalanParsedSource *source = (XalanParsedSource*) parsed_source;

  /* Grab the XML Document Root Node object */
  XalanNode *node = (XalanNode*) source->getDocument();
  if( node == NULL )
  {
     sprintf( err_buf, "The document is NULL" );
     return 0;
  }

  /* Create a Xalan DOM String for comparison */
  XalanDOMString *header_name = new XalanDOMString( "nletsHeader" );
  if( header_name == NULL )
  {
     sprintf( err_buf, "Program out of memory" );
     return 0;
  }

  /* Now we look for the NLETS Header element */
  node = FindDOMElement( node, header_name );

  /* Don't need the DOM String anymore so delete it */
  delete header_name;

  /* Make sure we found an nletsHeader node */
  if( node == NULL )
  {
     sprintf( error_buf, "No <nletsHeader> element found" );
     strncpy( err_buf, error_buf, err_len );
     return 0;
  }

/* Now node points to the NLETS Header element, so move to next sibling */
node = getNextSiblingElement( node );
if( node == NULL )
{
sprintf( error_buf, "No message descriptor element" );
strncpy( err_buf, error_buf, err_len );
return 0;
}


/* Grab the name of the element */
ConvertDOMStringToCharArray( node->getNodeName(), id->element, XML_ID_LEN );


   rest of function.....
}

Also I ran into a similar problem in Xerces under Win2K when trying to transcode a XMLString object. There are two ways to call the XMLString::transcode() function. One allocated an array and then I had to delete[] the returned array. This approach also seg faulted under Win2K. I replaced that code by doing my own malloc() and free() of a char array, and that seemed to have fixed the problem. I don't know if that helps at all, but if there is a version of the XalanDOMString::transcode() where the caller supplies a pre-allocated char array, I could give that a try. Thanks again for your help.

--Ryan





Reply via email to