This looks like C++ code, but DOMBuilder is a Java class, so I have no idea
what you're trying to do. You cannot mix Java and C++, that's for sure.
You also cannot modify the source document, so you cannot call
createTextNode() on the owner document of the context node.
There's no ideal solution for creating in Xalan-C++ right now. What we
need is an abstraction on XPathExecutionContext which can create fragments.
For the time being, the best solution is for your extension function to
have a XalanSourceTreeDocument instance as its "factory." The only problem
with this is that your function will have a hidden side-effect, and will
not be thread-safe. Thus, you'll need to install the function locally,
rather than globally. If your compiler supports the mutable keyword, make
sure you declare the XalanSourceTreeDocument instance as mutable. If you
compiler doesn't support mutable, then you'll have to cast-away const. If
you need complex fragments, you might want to build those by using
XalanSourceTreeContentHandler instance, which will let you build a fragment
by using SAX events.
Another option is to have a global XalanSourceTreeDocument instance and
synchronize access to it, but that requires more code, has a higher
overhead, and means that nodes will persist until you destroy the static
instance.
You'll also need to use the proprietary interface on
XalanSourceTreeDocument for creating nodes. Take a look at the header file
for more information.
By the way, the reinterpret_cast<> is not necessary here, as XalanText
derives from XalanNode.
Dave
wolfgang.schell@
gmx.net To:
[email protected]
cc:
02/11/2002 10:30 Subject: how to create nodes
from an external function
AM
Hi everybody!
I tried to create nodes (element/text) from within an external function but
always get a XalanDOMException with code 9 (i.e. NOT_SUPPORTED_ERR).
My approach was to get the context node's owner document and use it to
create new nodes.
The code roughly looks like this:
MyFunction::execute(XPathExecutionContext& executionContext,
XalanNode* context,
const XObjectPtr arg1,
const XObjectPtr arg2,
const Locator* locator) const
{
typedef
XPathExecutionContext::BorrowReturnMutableNodeRefList
BorrowReturnMutableNodeRefList;
XalanDocument* pDoc = context->getOwnerDocument();
BorrowReturnMutableNodeRefList theResult(executionContext);
pParameterName =
reinterpret_cast<XalanNode*>(pDoc->createTextNode(XalanDOMString("my text
node")));
theResult->addNode(pParameterName);
return executionContext.getXObjectFactory().createNodeSet(theResult);
}
I then had a look at the implementation of the XSLT document() function,
which simply uses the XPathExecutionContext's parseXML() method to read a
new
document, so that is not an option here.
My next step was to use a dombuilder to create the nodes I wanted to create
and it actually works. The problem is, that I don't know how to keep track
of
memory usage. If I delete the DOM builder right afterwards, the program
crashes (which seems quite logical to me ;-) but if I don't delete it, the
memory
probably won't be freed.
Any help either on how to use a DOMBuilder correctly in this situation or
other suggestions on how to create nodes from within an external function
are
greatly appreciated.
Cheers
Wolfgang
--
Wolfgang Schell
[EMAIL PROTECTED]
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net