Illegal characters in path when loading a string with XDocument

半腔热情 提交于 2019-12-18 12:05:52

问题


I have very simple XML in a string that I'm trying to load via XDocument so that I can use LINQ to XML:

 var xmlString = @"<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?>
 <person>Test Person</person>";

 var doc = XDocument.Load(xmlString); //'Illegal characters in path' error thrown here

I get an Illegal characters in path. error thrown when I try to load the XML; could someone please explain why this is happening? Thanks.


回答1:


You are looking for XDocument.Parse - XDocument.Load is for files not xml strings:

var doc = XDocument.Parse(xmlString); 



回答2:


Use

var doc = XDocument.Parse(xmlString); 



回答3:


Use this for XML String

        XDocument reader;
        using (StringReader s = new StringReader(**XmlResult**))
        {
            reader = XDocument.Load(s);
        }


来源:https://stackoverflow.com/questions/10586838/illegal-characters-in-path-when-loading-a-string-with-xdocument

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!