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;
}

int MyClass::EvaluateXPathExpression (unsigned short *xpath) {

  assert(xalan_document != 0);
  XalanDocumentPrefixResolver   thePrefixResolver(xalan_document);

        XPathEvaluator theEvaluator;

        // OK, let's find the context node...
        XalanNode* const        theContextNode = theEvaluator.selectSingleNode(
      theDOMSupport,
                        xalan_document,
                        XalanDOMString("/").c_str(),
                        thePrefixResolver);

  if (theContextNode == 0) {
    wprintf (L"No nodes matched the location path");
    return TAU_FAILURE;
  }
        else {

          // OK, let's evaluate the expression...
                const XObjectPtr        theResult( theEvaluator.evaluate( 
theDOMSupport,
          theContextNode,
          XalanDOMString(xpath).c_str(),
          thePrefixResolver));
    assert(theResult.null() == false);
    cout<<theResult->str();
    return 1;
                
        }
}

I have these
xalanc_1_10::XalanDocument* xalan_document;
xalanc_1_10::XalanSourceTreeDOMSupport theDOMSupport;
as private members of my class.

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.

Thanks in advance,
Smeeta

Reply via email to