Uploaded image for project: 'XalanC'
  1. XalanC
  2. XALANC-260

Abnormal program termination when trying to do a XPath query on Xerces DOM

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.5
    • Fix Version/s: None
    • Component/s: XPathC
    • Labels:
      None
    • Environment:
      Operating System: Windows NT/2K
      Platform: PC
    • Bugzilla Id:
      19598

      Description

      On Windows (Visual C++ 6.0), evaluating an XPath expression for a Xerces DOM
      causes an abnormal program termination. This code used to work on an earlier
      pre-release version of Xalan 1.5 (I pulled the source out of repository little
      more than a month back) but breaks in the official release. I have a sample
      file that recreates the issue.

      Here is the source to reproduce the issue (sorry, I am not sure how to attach a
      source file, so a cut and paste follows.....)

      // ---------------------------------------------------------------------------
      // Includes
      // ---------------------------------------------------------------------------

      #if defined(_MSC_VER)

      1. pragma warning(disable:4786 4239)
      2. include <xstring>
        #endif

      #include <xercesc/util/PlatformUtils.hpp>
      #include <xercesc/util/XMLString.hpp>
      #include <xercesc/dom/DOM.hpp>
      #include <iostream>
      #include <string>

      //Xalan & XPath include files
      #include <XalanDOM/XalanDocument.hpp>
      #include <XalanDOM/XalanElement.hpp>
      #include <PlatformSupport/DirectoryEnumerator.hpp>
      #include <PlatformSupport/DOMStringHelper.hpp>
      #include <DOMSupport/DOMServices.hpp>
      #include <XPath/XObjectFactoryDefault.hpp>
      #include <XPath/XPath.hpp>
      #include <XPath/XPathEnvSupportDefault.hpp>
      #include <XPath/XPathExecutionContextDefault.hpp>
      #include <XPath/XPathInit.hpp>
      #include <XPath/XPathProcessorImpl.hpp>
      #include <XPath/XPathFactoryDefault.hpp>
      #include <XPath/ElementPrefixResolverProxy.hpp>
      #include <XPath/XPathConstructionContextDefault.hpp>
      #include <XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
      #include <XalanSourceTree/XalanSourceTreeParserLiaison.hpp>
      #include <XercesParserLiaison/XercesDocumentBridge.hpp>
      #include <XercesParserLiaison/XercesDOMSupport.hpp>
      #include <XercesParserLiaison/XercesDocumentWrapper.hpp>

      XERCES_CPP_NAMESPACE_USE
      XALAN_CPP_NAMESPACE_USE

      using namespace std;

      // ---------------------------------------------------------------------------
      // This is a simple class that lets us do easy (though not terribly efficient)
      // trancoding of char* data to XMLCh data.
      // ---------------------------------------------------------------------------
      class XStr
      {
      public :
      // -----------------------------------------------------------------------
      // Constructors and Destructor
      // -----------------------------------------------------------------------
      XStr(const char* const toTranscode)

      { // Call the private transcoding method fUnicodeForm = XMLString::transcode(toTranscode); }

      ~XStr()

      { XMLString::release(&fUnicodeForm); }

      // -----------------------------------------------------------------------
      // Getter methods
      // -----------------------------------------------------------------------
      const XMLCh* unicodeForm() const

      { return fUnicodeForm; }

      private :
      // -----------------------------------------------------------------------
      // Private data members
      //
      // fUnicodeForm
      // This is the Unicode XMLCh format of the string.
      // -----------------------------------------------------------------------
      XMLCh* fUnicodeForm;
      };

      #define X(str) XStr(str).unicodeForm()

      // ---------------------------------------------------------------------------
      // main
      // ---------------------------------------------------------------------------

      int main(int argC, char* argV[])
      {
      // Initialize the XML4C2 system.
      try

      { XMLPlatformUtils::Initialize(); }

      catch(const XMLException& toCatch)

      { char *pMsg = XMLString::transcode(toCatch.getMessage()); cerr << "Error during Xerces-c Initialization.\n" << " Exception message:" << pMsg; XMLString::release(&pMsg); return 1; }

      DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X
      ("Core"));

      DOMDocument* doc = impl->createDocument(
      0, // root element namespace URI.
      X("Root"), // root element name
      0); // document type object (DTD).

      DOMElement* rootElem = doc->getDocumentElement();

      DOMElement* prodElem = doc->createElement(X("Child1"));
      rootElem->appendChild(prodElem);

      DOMText* prodDataVal = doc->createTextNode(X("GChild1"));
      prodElem->appendChild(prodDataVal);

      //Xerces DOM has been built, let's try to access that using XPath
      XercesDOMSupport theDOMSupport;
      XercesDocumentWrapper theWrapper(doc, false, false);
      wstring strQuery = L"/Root/Child1";

      // Initialize the XPath subsystem
      static XPathInit theInit;

      // configure the objects needed for XPath to work with the Xerces DOM
      XPathEnvSupportDefault theEnvSupport;
      XObjectFactoryDefault theXObjectFactory;
      XPathExecutionContextDefault theExecutionContext
      (theEnvSupport,theDOMSupport, theXObjectFactory);
      XPathFactoryDefault theXPathFactory;
      XPathProcessorImpl theXPathProcessor;

      XalanElement* rootXalanElem = theWrapper.getDocumentElement
      ();
      XalanNode* currentNode = theWrapper.mapNode(rootElem);

      // first get the context nodeset
      XPath* const contextXPath = theXPathFactory.create();
      //will be deleted by theXPathFactory destructor
      XPathConstructionContextDefault theXPathConstructionContext;
      theXPathProcessor.initXPath(*contextXPath,
      theXPathConstructionContext,
      XalanDOMString(strQuery.c_str
      ()),

      ElementPrefixResolverProxy(rootXalanElem, theEnvSupport,
      theDOMSupport));

      XObjectPtr xObj = contextXPath->execute(currentNode,
      ElementPrefixResolverProxy(rootXalanElem,theEnvSupport,
      theDOMSupport),
      theExecutionContext);

      if( xObj->getType() != XObject::eTypeNodeSet )

      { //No results returned... cout << "No results were returned...." << endl; }

      else

      { const NodeRefListBase& nodeset = xObj->nodeset(); //ok, now we get the matching xalan node, add to the vector size_t len = nodeset.getLength(); cout << "Number Nodes Returned: " << len << endl; }

      doc->release();
      XMLPlatformUtils::Terminate();
      return 0;
      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              rchauhan@micron.com Ravin Chauhan
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: