Re: [xml] manipulating tree causes Seg fault

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

After finding the specified text node, "zabcz" (lets call this text
node: to_be_replaced), I want to replace it with "za<text:span

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="";>za<text:span

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

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.

Michael Ludwig

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