This project has moved. For the latest updates, please go here.

Output Formatting

Topics: User Forum
Dec 4, 2006 at 10:23 PM
Hey gang.

I was wondering if anyone knows of a way to format the OuterHtml so it is more "pretty". So if you have the following:


And turns it into:

I'm sure everyone likes their own different style but if I knew how to insert tabs and new lines properly, I could do this properly.

Would I simply #1 re-format OuterHtml or #2 do something more proper such as adding new HtmlNode's to the document with proper formatting?

How would I do #1 or #2 depending which is better or any other way you think would be more appropriate?

Any help would be greatly appreciated.

Thanks and take care.
Dec 4, 2006 at 10:24 PM
Oops this editor is too simple ;) I meant formatted like:

Dec 12, 2006 at 7:22 AM

That's a good question (ahh there are so many good questions :-).
It's not done out of the box because... it's not so simple! It's a matter of balance between compatibility (change nothing) and normalization (change so it looks or behave or complies better).

The Html Agility Pack was clearly design with compatibility in mind. That's why it remembers all whitespaces, even the one that should not exists, or must not exists. It knows very little about what HTML really is.

Sometimes, when you remove or add whitespaces, and you browse the modified page again in IE or FF, you just realized it's not rendered the same, in IE or FF, or another one.

So, yes, it's feasible, but not quite the same story if you want to make absolutely sure you don't change the page rendering.