Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal characters in path when loading a string with XDocument

Tags:

c#

xml

.net-4.0

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.

like image 931
BoundForGlory Avatar asked May 14 '12 15:05

BoundForGlory


2 Answers

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

var doc = XDocument.Parse(xmlString); 
like image 176
BrokenGlass Avatar answered Nov 19 '22 09:11

BrokenGlass


Use

var doc = XDocument.Parse(xmlString); 
like image 42
Cinchoo Avatar answered Nov 19 '22 10:11

Cinchoo