DawidRybarczyk
DawidRybarczyk

Reputation: 45

XML file loading in c#

I have a problem with loading an XML file by:

XDocument.Load("file.xml");

Here are some of the errors:

error CS1056: Unexpected character '®'
error CS1056: Unexpected character '™'
error CS1056: Unexpected character '、'
error CS0116: A namespace cannot directly contain members such as fields or methods
error CS1003: Syntax error, ']' expected
error CS1518: Expected class, delegate, enum, interface, or struct

So I wanted to ask if there is any way to fix this easily?

Upvotes: 1

Views: 294

Answers (2)

Chuck Savage
Chuck Savage

Reputation: 11955

Try putting this as your first line in the XML file.

<?xml version="1.0" encoding="UTF-8"?>

Upvotes: 0

Romano Zumb&#233;
Romano Zumb&#233;

Reputation: 8079

You need to escape those characters in the xml file. The best way would be to do this uppon generation of the XML File. But if that is no option for you you coul read in the file line by line, replace the charcters by the corresponding escap sequence and write the lines back to another file. This file would be the source for your XDocument.

Upvotes: 1

Related Questions