Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-05

renaming XML element

2 messages · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Santhoff

Hi,

since I'm only rarely using XML and the DOM unit I have to ask:

I need to rename an element inside an XML tree. I've learned that elements are immutable in the DOM implementation, so renaming has to be done by

- makeing a new element with the new name
- copying over the complete subtree (childs, attributes, #text)
- attaching the new element directly after the to be renamed one
- removing the old element node

Is this correct?

And how would I do that using the DOM implementation, I'm really not sure what methods to use ...

Example
-------
Now:

<doc>
<oldnode>whatever or nothing</oldnode>
<child1></child1>
...
<nextsibling></nextsibling>
...
</doc>

Afterwards:

<doc>
<newnode>whatever or nothing</newnode>
<child1></child1>
...
<nextsibling></nextsibling>
...
</doc>

All of the nodes except root may have attributes, text content and child nodes.

Marc

Marc Santhoff

Reply by email

Marc Santhoff
to Marc Santhoff

Sorry, I messed up the structure of the example ...

Marc Santhoff wrote 8 lines
Example ------- Now: <doc> <oldnode>whatever or nothing <child1></child1> ...

 </oldnode>

Show quoted text 10 lines
<nextsibling></nextsibling> ... </doc> Afterwards: <doc> <newnode>whatever or nothing <child1></child1> ...

</newnode>

<nextsibling></nextsibling> ... </doc>
Marc Santhoff

Reply by email