0

I need to insert an element in the middle of another element's text. Given here is "before" and "after" that I want

Before

<element1> This is content of element1 </element1>

After

<element1> This is <element2></element2> content of element1 </element1>

Any ideas how to achieve this....I am using Java Dom API.

OKOK
  • 259
  • 2
  • 16

1 Answers1

1

I suspect you'll need to remove the existing text node(s), and then create three new nodes:

  • The text before <element2>
  • <element2>
  • The text after <element2>

Add all of those to <element1> after removing the existing text node(s).

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • I was hoping I would not need to do that. – OKOK Dec 18 '13 at 11:41
  • @user1752247: Why? You need to control exactly where it's split anyway - and this will be a tiny amount of work. (It's really not that hard to add the nodes.) Have you tried implementing this and run into any problems? – Jon Skeet Dec 18 '13 at 11:47