Smeeta Jalan wrote:
Hi,

I am using Xalan-C 1.10 and Xerces 2.7. I have to write a wrapper
class whose functions gives me the results of XPath queries.
I got an example in the samples SimpleXPathAPI which serves my
purpose. But I have few problems. I wanted to  split the entire thing
into 2 functions so that the instance of XalanDocument gets created
only once.
I have a private function which returns me the xalan_document and
another public function which should give me the result of an XPath
query. (XPath query being the parameter of the function).

I am pasting the sample of my code to give you idea, but this doesn't
work.It gives me a run time error at this line:
XalanDocumentPrefixResolver     thePrefixResolver(xalan_document);
saying some access violation reading some location.

int MyClass::create_xalan_document(unsigned short* filename) {

        // Initialize the XalanSourceTree subsystem...
        XalanSourceTreeInit     theSourceTreeInit;

        // We'll use these to parse the XML file.
        XalanSourceTreeParserLiaison theLiaison(theDOMSupport);

        // Hook the two together...
        theDOMSupport.setParserLiaison(&theLiaison);

        const XalanDOMString theFileName(filename);

        // Create an input source that represents a local file...
        const LocalFileInputSource theInputSource(theFileName.c_str());

        // Parse the document...
        xalan_document = theLiaison.parseXMLStream(theInputSource);
        assert(xalan_document != 0);
  return 1;
}


The documentation for XMLParserLiaison::parseXMLStream() says the following:

/**
 * Parse the text pointed at by the reader as XML, and return a DOM
 * Document interface.  It is recommended that you pass in some sort of
 * recognizable name, such as the filename or URI, with which the reader
 * can be recognized if the parse fails.
 *
 * The liaison owns the XalanDocument instance, and will delete it when
 * when asked (see DestroyDocument()), or when the liaison is reset, or
 * goes out of scope.
 *
 * @param reader     stream that should hold valid XML
 * @param identifier used for diagnostic purposes only, some sort of
 *                   identification for error reporting, default an empty
 *                   string
 * @return DOM document created
 */

So, the XalanDocument instance is being destroyed when the XalanSourceTreeParserLiaison you create on the stack in your function is destroyed. That happens when the function exits.

If you really want to wrap these calls in your class, then make that instance, and the XalanSourceTreeDOMSupport instance it needs members of your class.

Note that it's not generally a good idea to use the "Init" class in your code. The best thing to do is to call XalanTransformer::initialize() right after you call PlatformUtils::Initialize(), when your application starts.


...


Can you tell me where am I going wrong?
I couldn't make out things very well from the documentation available.

I also tried initializing XalanSourceTreeInit in a main function
called before these two but it doesn't help.

As I said previously, the best thing to do is to call XalanTransformer::initialize() in main(), and remove any usage of the "Init" classes.


Thanks in advance,
Smeeta


Dave

Reply via email to