Illegal characters in path when loading a string with XDocument

29,415

Solution 1

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

var doc = XDocument.Parse(xmlString); 

Solution 2

Use

var doc = XDocument.Parse(xmlString); 
Share:
29,415

Related videos on Youtube

BoundForGlory
Author by

BoundForGlory

Hello and Greeting from Dallas, I graduated from the University of North Texas with a degree in Electronics Engineering Technology. I'm a software engineer who specializes in ASP.NET MVC, web forms, wpf and winforms. I also do mobile development for Android and iOS. Most importantly, I am loved by God almighty and without Him, I am absolutely nothing. Thanks for reading this and may God bless.

Updated on July 16, 2022

Comments

  • BoundForGlory
    BoundForGlory almost 2 years

    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.

  • Don Cheadle
    Don Cheadle over 8 years
    and for XmlDocument it's XmlDocument.LoadXml(xmlString)