3

I am using org.w3c.dom APIs to parse a a HTML fragment which is composed of a series of

tags with various markups in between. I am trying to ingest the HTML fragment into a org.w3c.dom.Document and splitting on the HTML into the <p>..</p>

I can easily get a NodeList of the <p> tags (doc.getElementsByTagName("p")) however from the NodeList I am having trouble getting the equivalent of "innerHTML" and "outerHTML" of the elements in the NodeList.

How can i get the equivalent of innerHTML and outerHTML w the org.w3c.dom APIs? (I dont want to introduce another dependency such as JSoup)

empire29
  • 3,729
  • 6
  • 45
  • 71

1 Answers1

1

inner/outerHTML are just convenience methods which essentially serialize document fragments to/from strings through DOM parsers and serializers. You can achieve the same results "by foot" by using the DOM Load/Save APIs

see this answer how to use them.

Community
  • 1
  • 1
the8472
  • 40,999
  • 5
  • 70
  • 122
  • ... and see [this answer](https://stackoverflow.com/a/5948326) for specific examples of using DOM Load/Save APIs for this task – Igor Nardin Sep 18 '19 at 16:32