Hi! I think I hit a stumbling point. I am using the Xerces SAX parser to parse an XML file and creating the Xalan SAX events with some of the XML data. However, consider the following XML:
<elem1><child1></elem1> I have the need to generate XML output similar to the following: <derive1a><child1></derive1a><derive1b><child1></derive1b> ... <derive1n><child1></derive1n> In other words, if I run across child1, I may need to generate n derive1n tags in the Xalan output, each with child1. Notice that the child determines which parent nodes need to be created! The tree may run very deep, too, requiring this to occur at many different depths of the tree. That was the original reason that I wanted to access the non-const methods in the Xalan source tree, so that I could potentially duplicate elements if required. Is there any way to do this??? I was hoping to avoid generating a tree structure with all aforementioned structure, only to have to turn around and traverse that tree, calling ContentHandler::startDocument(...), etc., because two trees are created. Any ideas? Thanks! Matt Hanson! -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, December 11, 2001 12:31 PM To: [email protected] Subject: RE: createElement() inside external function segfaults 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. 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 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
