i have html <div><h1> hello hi</div> <div>hi </p></div>
required output : <div><h1> hello </h1></div> <div><p>hi </p></div>
using html agility pack possible fix kind of similar issues missing closing , opening tags?
the library isn't intelligent enough create opening p
put it, it's intelligent enough create missing h1
. , in general, creates valid html always, not 1 expect.
so code:
htmldocument doc = new htmldocument(); doc.load(yourhtml); doc.save(console.out);
will dump this:
<div><h1> hello hi</h1></div> <div>hi <p></div>
which not want, valid html. can add little trick this:
htmlnode.elementsflags["p"] = htmlelementflag.closed; htmldocument doc = new htmldocument(); doc.load(yourhtml); doc.save(console.out);
that dump this:
<div><h1> hello hi</h1></div> <div>hi <p></p></div>