Fix xml file using C#

  • Thread starter Thread starter Rookie
  • Start date Start date
R

Rookie

I've a xml-file where not all elements are properly closed.
Is it possible to automatically close all open elements using c#.

Regards,

Rookie
 
I've a xml-file where not all elements are properly closed.
Is it possible to automatically close all open elements using c#.

Write some code that reads the file, inserts the missing stuff
and writes a new file.

The tricky part is to determine when to insert something, but
if you know the current format and the desired format, then
it is possible.

But there is not general non-format-dependent way of doing it,
because the same not valid XML could be multiple different
variants of valid XML.

Given that it is not valid XML, then you can of course not use
anything intended to read valid XML.

Arne
 
I've a xml-file where not all elements are properly closed.
Is it possible to automatically close all open elements using c#.

No, you have to walk the file and find the improperly formed parts and fix
them.

The XML classes can help you if you have a schema, by identifying the
problems. There are also third party components for this that might even
work better (perhaps even a component that can "fix" these issues?).

Ultimately, you have to find the problem spots and fill in. And, yes, this
is a pain.

Another option is figuring out why the "XML" is not properly formed and
eliminating the issue on that end.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top