0

I know google is full of this, but I couldn't make it work after hours of trying.

So here's foo.xml:

<Root>
    <Child>a</Child>
</Root>

XDocument.Load("foo.xml") works great.

Here is bar.xml:

<Root>
    <Child>á</Child>
</Root>

XDocument.Load("bar.xml") throws a System.Xml.XmlException:

{"Invalid character in the given encoding. Line 2, position 9."}

How should I progress?

nopara73
  • 502
  • 6
  • 24
  • Have you checked this thread http://stackoverflow.com/questions/8275825/how-to-prevent-system-xml-xmlexception-invalid-character-in-the-given-encoding? – Pylyp Lebediev Jul 26 '15 at 18:17
  • 2
    Make sure to save your file as UTF-8. – poke Jul 26 '15 at 18:18
  • 2
    Your XML is perfectly valid, so this has nothing to do with XML. It's likely to do with encoding of the file. – Charles Mager Jul 26 '15 at 18:25
  • Encoding to UTF8 solved my problem. However it did only work with in the example above, with my original xml, it didn't. Since I was constalntly testing on that before this stackoverflow post, I couldn't make it work. Now the trick was to copypaste the content to a new file, encode to UTF8 and it magically started to work. Thank you guys! – nopara73 Jul 26 '15 at 18:50

1 Answers1

0

No magic here, I just had to encode the xml to UTF8.

nopara73
  • 502
  • 6
  • 24