0

I'm trying to pretty print xml that I receive in my program, without parsing it beforehand. The reason for that, is that many of the XML formats I get have illegal characters in them, etc.

What I would like is purely a tool or framework or code - if exists - that purely indents the attributes according to the "</" brackets, etc. The same as Notepad++ does for example or this website.

I've tried all the different xml parsers .NET has to offer, but they always need to successfully parse it before further manipulation.

Is there something out there for this kind of application or would I need to write something "from scratch"?

EDIT I just found out by trying -> When I save the XML code as "name.xml" and then drag the file in the Browser, it gets formatted automatically. This would be a solution if necessarry, but only if it were possible to simulate the dragging into the browser. Just by opening it with

Process.Start("chrome.exe", filePath);

does not work either.

Oliver
  • 109
  • 1
  • 12
  • 2
    If you have illegal characters then it's not valid XML, and no pretty-print will deal with it. Please give a [mcve], show us your XML in the question (copy/paste *exactly*) – Charlieface Jun 03 '22 at 10:02
  • You might take a look at [How to parse invalid (bad / not well-formed) XML?](https://stackoverflow.com/q/44765194) and/or [Parse malformed XML](https://stackoverflow.com/q/996552), – dbc Jun 03 '22 at 17:03

0 Answers0