Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从我的Api读取Xml,因为根级别的错误数据无效。第1行,位置1_C#_Xml_Xmlreader - Fatal编程技术网

C# 无法从我的Api读取Xml,因为根级别的错误数据无效。第1行,位置1

C# 无法从我的Api读取Xml,因为根级别的错误数据无效。第1行,位置1,c#,xml,xmlreader,C#,Xml,Xmlreader,每次我试图从数据库web api(我创建的)中提取XML时,XMLTextReader.Read()都会给出一个错误提示 根级别的数据无效。第1行,位置1 我的XmlReader代码是: String URLString = @"https://localhost:44331/api/voter/4220180288473"; XmlTextReader reader = new XmlTextReader(URLString); reader.MoveToNextAttribute(); wh

每次我试图从数据库web api(我创建的)中提取XML时,XMLTextReader.Read()都会给出一个错误提示

根级别的数据无效。第1行,位置1

我的XmlReader代码是:

String URLString = @"https://localhost:44331/api/voter/4220180288473";
XmlTextReader reader = new XmlTextReader(URLString);
reader.MoveToNextAttribute();
while (reader.Read())
{
     // Do some work here on the data.
    Console.WriteLine(reader.Name);
}
Console.ReadLine(); 
我的XML:


泽山穆斯塔法
1234
基尔
4220180288476
假的

我运行了您的代码,当我使用此url字符串时,它似乎工作正常:确保数据开头没有任何白色字符。