This is the exact same issue.  XalanSourceTreeDocument does not support the
standard DOM factory calls for creating nodes and modifying the tree.  You
need to build it through SAX events, because the tree must be built in
document order.  Allowing standard DOM calls would also allow random
construction of the tree, which is not supported.

Note that this does not affect _read-only_ access to the tree through DOM
calls.  This can be summarized by stating that most const methods of the
XalanDOM hierarchy are supported, while _none_ of the non-const ones are
supported.

You can easily fix your code by calling the startElement() and endElement()
member functions of XalanDocumentBuild, rather than creating a
XalanSourceTreeElement instance and appending it.

Dave



                                                                                
                              
                      Matthew James                                             
                              
                      Hanson                   To:      
[email protected]                          
                      <matthew.hanson@         cc:      (bcc: David N 
Bertoni/CAM/Lotus)                      
                      wcom.com>                Subject: RE: createElement() 
inside external function          
                                               segfaults                        
                              
                      12/11/2001 11:53                                          
                              
                      AM                                                        
                              
                                                                                
                              
                                                                                
                              



This issue may relate to a technique that I have been trying, but NOT part
of an extension function.  I have been trying to avoid using SAX events
with
XalanSourceTreeContentHandler.  Rather, I was hoping I could have access to
the underlying XalanSourceTreeDocument returned from
XalanDefaultDocumentBuilder->getDocument().  No exceptions are thrown, but
XalanSourceTreeDocument->createNodeElement(...) doesn't output my data.
Here is the code:

             AttributesImpl attrs;
             XalanDOMString elemNm, attrNm, attrVal;
             const XalanDOMString attrType("CDATA");

             XalanDocumentBuilder* const docBldr =
theXalanTransformer.createDocumentBuilder();
             if (docBldr)
             {
                         XalanSourceTreeDocument * doc(static_cast <
XalanSourceTreeDocument * >
(docBldr->getDocument()));
                         if (doc)
                         {
                                     std::cout << "have
XalanSourceTreeDocument\n";
                                     elemNm = "name1";
                                     attrNm = "attr1Nm";
                                     attrVal = "attr1Val";
                                     attrs.addAttribute(c_wstr(attrNm),
c_wstr(attrType), c_wstr(attrVal));
                                     attrNm = "attr2Nm";
                                     attrVal = "attr2Val";
                                     attrs.addAttribute(c_wstr(attrNm),
c_wstr(attrType), c_wstr(attrVal));
                                     XalanSourceTreeElement *
element(doc->createElementNode(attrNm.c_str(),
attrs));
                                     doc->appendChildNode(element);
                         }
             }

Am I also misunderstanding the usage of these classes.  I hope really hope
to have access to the underlying tree so that I can get attributes, values,
of an element to be used by its child elements.

Thanks!!!

 -----Original Message-----
From:              [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Sent:        Tuesday, December 11, 2001 9:30 AM
To:          [email protected]
Subject:           Re: createElement() inside external function segfaults


It's not a bug in Xalan, it's a bug in your application and your
understanding of XSLT.

You are not allowed to modify the source tree in any way, including
creating new nodes.  The function you're calling is throwing an exception
which you're not catching.  See the class XalanDOMException and the source
code for XalanSourceTreeDocument for more information on what's being
thrown.

Currently, there's no way in Xalan-C to create new nodes in an extension
function.  We can certainly make something like that available, but it
wouldn't be through DOM APIs.  Insteand, it would be through getting a SAX
handler and sending events.  If this functionality is important to you,
then we should discuss the best way to implement this.

Dave




                      Edwin Pratomo
                      <[EMAIL PROTECTED]         To:
[email protected]
                      .org>                    cc:
                      Sent by:                 Subject: createElement()
inside external function segfaults
                      [EMAIL PROTECTED]
                      m


                      12/11/2001 09:56
                      AM


Hi,

I tried to create new elements inside an external function, but
createElement() segfaults:

virtual XObjectPtr
execute(
        XPathExecutionContext&          executionContext,
        XalanNode*                      context,
        int                             /* opPos */,
        const XObjectArgVectorType&     args)
{
    XalanDocument *doc = context->getOwnerDocument();
    XalanElement *new_node = doc->createElement(XalanDOMString("foo"));
    ...

Is this a bug? any workaround?

rgds,
Edwin.

--
CPAN home: http://search.cpan.org/search?author=edpratomo







Reply via email to