[EMAIL PROTECTED] wrote:
> 
> Hi Matt,
> 
> Your error was not a fundamental error regarding XSLT.  Rather, you were
> attempting to get at implementation classes by casting, which is always a
> bad thing to do.  The implementations are hidden because you shouldn't rely
> on implementation-level behavior or APIs at the application level.
> 
> XalanDocumentBuilder was designed as an abstraction to allow a source tree
> to be built through SAX events, rather than by parsing a document.  You
> were mis-using it by casting to get at implementation classes.
> 
> The other person was trying to modify the source tree, which is explicitly
> forbidden by the XSLT processing model.  There is nothing in the XSLT
> recommendation that describes how this source tree is built, or any other
> such implementation-level details.

Well, actually what I was trying to do is to create new nodes and return
it as a nodeset. 
I didn't mean to modify the XalanSourceTreeDocument object to which the
context node belongs to. 
I've tried also to create another instance of XalanSourceTreeDocument
and invoke createTextNode(), but this also threw
NO_MODIFICATION_ALLOWED_ERR. 
Which document class I can use to do such thing? Or is it completely
impossible? 

I saw in Xalan-J's tokenize() function:
    try
    {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      lDoc = db.newDocument();
    }
    catch(...) { ... }

    NodeSet resultSet = new NodeSet();

    while (lTokenizer.hasMoreTokens())
    {
      resultSet.addNode(lDoc.createTextNode(lTokenizer.nextToken()));
    }

so I think it's also doable in Xalan C++.

rgds,
Edwin.

>                       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 02:13
>                       PM
> 
> 
> 
> Using the SAX calls and const methods will be no problem!  I assume, then,
> that my original strategy of building up a tree was actually a
> misunderstanding of XSLT, similar to the other post.  What fundamental
> knowledge was I missing about XSLT?
> 
> Thanks!
> Matt Hanson!
> 
>  -----Original Message-----
> From:              [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> Sent:        Tuesday, December 11, 2001 10:40 AM
> To:          [email protected]
> Subject:           RE: createElement() inside external function segfaults
> 
> 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

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

Reply via email to