1

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?

2

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Here is also solution how to achieve that what Romano suggested.
0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.