Re: [xml] manipulating tree causes Seg fault



Michael,

You're right.

The sole reason for the creation of a new tree, and adding it in, then "peeling" the root of the new tree, is just the simplest way of doing it with the way the tools work that we have set up.

I agree with your proposed solution. What it sounds like is I might have to do some rewriting to the way our tools actually "peel" elements.
My second question, is this (after working on this for a while).
Assuming we are using the same method I explained previously:
If a tree (called tree1) with a name space declaration is added to an existing tree (called tree2), with more name spaces (including the one from tree1). If the node, with the name space declaration from tree1 is removed, the the namespaced elements from tree1, now in tree2 should not be effected right?

Thanks
Nick


Michael Ludwig wrote:
Nick Lang schrieb:

Find a specific text node. Replace with an element node (containing a
text node).

Hi Nick,

let's leave out all the regex stuff; it does not seem relevant to the
problem.

After finding the specified text node, "zabcz" (lets call this text
node: to_be_replaced), I want to replace it with "za<text:span
text:style-name='bold'>b</text:span>cz"

That is: Text node "za", element node with text child, text node "cz".

The process by which I'm adding this new element, is by creating a new
xml document with a temp root node.
<temp xmlns:text="http://openoffice.org/2000/text";>za<text:span
text:style-name='bold'>b</text:span>cz</temp>

That's unnecessary.

I then add this new document to the original document as a child, of
the parent of "to_be_replaced". (lets call this parent, foster_parent)

You need to import it. You can't simply add nodes originating in another
document.

But you don't need an additional document, which makes things more
complicated. All you need is to add three nodes in the right position.

(1) Remove the node you want to replace.
(2) Find out whether or not there are more nodes after your insertion
    point. If so, use insertBefore(); if not, simply use append().
(3) Create your nodes as you go using the very same document you want
    to adopt them.
(4) Done.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]