0

I need to prepend HTML to existed XOM element. HTML represented as a String.

Here are my actions

  1. Parse String into XOM Document
  2. Remove root element(X) from Document
  3. Prepend X to desired target element (Y)

I get an exception

nu.xom.WellformednessException: Cannot remove the root element
    at nu.xom.Document.removeChild(Unknown Source)
    at nu.xom.Node.detach(Unknown Source)

X element HTML

<div>
  Some test text
</div>
aleks.n.fedorov
  • 322
  • 1
  • 2
  • 10

1 Answers1

0

Current XOM implementation does not allow to remove root node.

To achieve desired goal it is need to add fake root and then detach required node.

In a context of mentioned step set:

Replace step 2 with next

  1. Add fake root element - document.setRootElement(new Element("div"))
  2. Detach desired element - element.detach()
aleks.n.fedorov
  • 322
  • 1
  • 2
  • 10