You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Han Ming Ong <ha...@mac.com> on 2003/07/19 03:03:59 UTC

Re: Antwort: Can I change the nodeset that is returned by Xalan XPath?

So I tested the same piece of code with RedHat 9. There is no problem. 
Certainly, it is a problem happening on Mac OS X. I may be missing some 
flags when I compiled it.

I have tried

-DXALAN_USE_XERCES_LOCAL_CODEPAGE_TRANSCODERS

and my XPathWrapper program always fails with memory problem in 
getNamespaceURI()

If I don't use XALAN_USE_XERCES_LOCAL_CODEPAGE_TRANSCODERS, then I have 
a transcoding error in XPathInit.

Do anyone has any good ideas please?

On Wednesday, July 9, 2003, at 10:25  PM, Han Ming Ong wrote:

> Joerg,
>
> 	Thanks for the pointer. I just realized that I had been doing pretty 
> much what you wrote here. I kept getting an exception which I couldn't 
> really understand, which was why I asked to see if my bearings were 
> right. It seems like I was doing the right thing already. Well, that 
> said, I'm still getting an exception, maybe you or David can help 
> again :-).
>
> Exception:  EXC_BAD_ACCESS (0x0001)
> Codes:      KERN_INVALID_ADDRESS (0x0001) at 0x01a37fa8
>
> Thread 0 Crashed:
>  #0   0x3505ff0c in 
> xalanc_1_5::XercesElementWrapper::getNamespaceURI() const 
> (XercesElementWrapper.cpp:289)
>  #1   0x3509e154 in 
> xalanc_1_5::XPath::NodeTester::matchLocalName(xalanc_1_5::XalanNode 
> const&) const (XPath.cpp:5288)
>  #2   0x3509dcd8 in 
> xalanc_1_5::XPath::NodeTester::testElementNCName(xalanc_1_5::XalanNode 
> const&, xalanc_1_5::XalanNode::NodeType) const (XPath.cpp:5160)
>  #3   0x35289678 in 
> xalanc_1_5::XPath::NodeTester::operator()(xalanc_1_5::XalanNode 
> const&, xalanc_1_5::XalanNode::NodeType) const (XPath.cpp:2198)
>  #4   0x3509a8c0 in 
> xalanc_1_5::XPath::findChildren(xalanc_1_5::XPathExecutionContext&, 
> xalanc_1_5::XalanNode*, int, int, xalanc_1_5::MutableNodeRefList&) 
> const (XPath.cpp:3754)
>  #5   0x350984d4 in 
> xalanc_1_5::XPath::step(xalanc_1_5::XPathExecutionContext&, 
> xalanc_1_5::XalanNode*, int, xalanc_1_5::MutableNodeRefList&) const 
> (XPath.cpp:2863)
>  #6   0x35288d50 in 
> xalanc_1_5::XPath::locationPath(xalanc_1_5::XalanNode*, int, 
> xalanc_1_5::XPathExecutionContext&, xalanc_1_5::MutableNodeRefList&) 
> const (XPath.cpp:1112)
>  #7   0x3509677c in 
> xalanc_1_5::XPath::locationPath(xalanc_1_5::XalanNode*, int, 
> xalanc_1_5::XPathExecutionContext&) const (XPath.cpp:2374)
>  #8   0x35090bbc in 
> xalanc_1_5::XPath::executeMore(xalanc_1_5::XalanNode*, int, 
> xalanc_1_5::XPathExecutionContext&) const (XPath.cpp:391)
>  #9   0x350906c0 in 
> xalanc_1_5::XPath::executeMore(xalanc_1_5::XalanNode*, int, 
> xalanc_1_5::XPathExecutionContext&) const (XPath.cpp:303)
>  #10  0x3508ff38 in xalanc_1_5::XPath::execute(xalanc_1_5::XalanNode*, 
> xalanc_1_5::PrefixResolver const&, xalanc_1_5::XPathExecutionContext&) 
> const (XPath.cpp:167)
>  #11  0x350a169c in 
> xalanc_1_5::XPathEvaluator::evaluate(xalanc_1_5::DOMSupport&, 
> xalanc_1_5::XalanNode*, xalanc_1_5::XPath const&, 
> xalanc_1_5::PrefixResolver const&, xalanc_1_5::XPathEnvSupport&) 
> (XPathEvaluator.cpp:481)
>  #12  0x350a1514 in 
> xalanc_1_5::XPathEvaluator::evaluate(xalanc_1_5::DOMSupport&, 
> xalanc_1_5::XalanNode*, unsigned short const*, 
> xalanc_1_5::PrefixResolver const&, xalanc_1_5::XPathEnvSupport&) 
> (XPathEvaluator.cpp:448)
>  #13  0x350a0d58 in 
> xalanc_1_5::XPathEvaluator::evaluate(xalanc_1_5::DOMSupport&, 
> xalanc_1_5::XalanNode*, unsigned short const*, 
> xalanc_1_5::XalanElement const*) (XPathEvaluator.cpp:296)
>  #14  0x350a05cc in 
> xalanc_1_5::XPathEvaluator::selectSingleNode(xalanc_1_5::DOMSupport&, 
> xalanc_1_5::XalanNode*, unsigned short const*, 
> xalanc_1_5::XalanElement const*) (XPathEvaluator.cpp:141)
>
> Environment:
> 	Mac OS X 10.2.6
> 	gcc - 3.1
> 	Xerces 2.2 compiled with -w -O0 -DXML_USE_INMEM_MESSAGELOADER 
> -DXML_USE_MACOS_UNICODECONVERTER -DXML_USE_NETACCESSOR_URLACCESSCF
> 	Xalan 1.5 compiled with -w --O0 
> -DXALAN_USE_XERCES_LOCAL_CODEPAGE_TRANSCODERS 
> -DXALAN_STRICT_ANSI_HEADERS
> 	Both build as a "framework" (in Mac's sense, similar to dynamic 
> library).
>
> 	I noticed that it always fails with the same exception and here's 
> what I try to do in gdb:
>
> (gdb) p m_xercesNode
> warning: can't find class named `xalanc_1_5::XercesElementWrapper', as 
> given by C++ RTTI
> $4 = (const DOMElementType * const) 0x1a77fa8
> (gdb) p *m_xercesNode
> warning: can't find class named `xalanc_1_5::XercesElementWrapper', as 
> given by C++ RTTI
> Cannot access memory at address 0x1a77fa8
>
> 	My C++ has been a bit rusty as I'm been doing Objective-C and Java, 
> how can I figure out what's wrong?
>
> 	Note that I have also tested with the Xalan-CVS + Xerces 2.3 and I 
> still get an exception (although I got to admit that I can't remember 
> if it is the same exception).
>
> Thanks, Han Ming
>
> On Monday, July 7, 2003, at 03:03  AM, Joerg.Seidler@it-informatik.de 
> wrote:
>
>>
>>
>> Hi,
>>
>> having received competent help from the community,
>> maybe I can be of help too.
>>
>> We have the same scenario and use Xalan-C mainly for its XPath 
>> capabilities.
>> We do something like this:
>>
>> void select(xercesc::DOMNode * &node,
>>             const std::string &xpath,    // XPath expression 
>> evaluating to a node set
>>             xercesc::DOMDocument &document) {
>>
>>     XercesDOMSupport dom_support;
>>     XercesParserLiaison parser_liaison;
>>
>>     XalanDocument *xalan_document = 
>> parser_liaison.createDocument(&document, false, true);
>>
>>     XalanNode * root_context_node = xalan_document;
>>
>>     XalanElement *namespace_node = 
>> xalan_document->getDocumentElement();
>>
>>     const XalanDOMString expression(xpath.c_str());
>>
>>     DOMNode *target= 0;
>>
>>     XPathEvaluator evaluator;
>>
>>     const XalanNode* found = evaluator.selectSingleNode(
>>                                             dom_support,
>>                                             root_context_node,
>>                                             expression.c_str(),
>>                                             namespace_node);
>>
>>     if (found) {
>>
>>         XercesDocumentWrapper *xerces_document_wrapper =
>>                parser_liaison.mapDocumentToWrapper(xalan_document);
>>
>>        DOMNode const *const_target = 
>> xerces_document_wrapper->mapNode(node);
>>        target = const_cast<DOMNode *>(const_target);
>>     }
>>
>>     node = target;
>> }
>>
>> Now your calling code can do with the passed DOMNode pointer what
>> it wants, maybe modify it.
>>
>> Just observe the remark from David Bertoni if you keep your 
>> XercesParserLiaison
>> and XercesDocumentWrapper outside the function performing the 
>> selectSingleNode-call:
>>
>>> If you're going to use XercesDocumentWrapper, make sure you always 
>>> re-build
>>> the wrapper after you've made modifications to the document, and 
>>> make sure
>>> you pass true for the buildWrapper parameter.
>>
>> By the way, this works also for XPathEvaluator::selectNodeList()
>> to get a complete node set and for XPathEvaluator::evaluate() if
>> you're interested in non-node set XPath types such as string, number
>> and boolean.
>>
>> Hope this helps.
>>
>> Bye
>>
>> Joerg
>>
>> joerg.seidler@it-informatik.de
>>
>>
>>
>>
>>
>