简体   繁体   中英

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?

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.

尝试将其作为XML文件的第一行。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM