Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

C# read data from XML File

(0) ShareShare
ReportReport
Posted on by 445

Hello Experts,

i try to read data from XML File but i always get an Error: Data at the root level is invalid. Line 1, position 1.

The Error must be there:

XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
doc.PreserveWhitespace = false;
XmlNode root = doc.DocumentElement;


Can someone help me? 

Kind Regards
Léon

*This post is locked for comments

  • BlackBeard Profile Picture
    BlackBeard 445 on at
    RE: C# read data from XML File

    Hi Goutam,

    i allready have this in my code...

    But it dont works... -.-

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: C# read data from XML File

    Hi Leon ,

    There may be conversion issue with UTF8. Please try with this 

    string _byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
    if (xml.StartsWith(_byteOrderMarkUtf8))
    {
        xml = xml.Remove(0, _byteOrderMarkUtf8.Length);
    }


  • BlackBeard Profile Picture
    BlackBeard 445 on at
    RE: C# read data from XML File

    The problem is that my XML Data looks very strange from the format.

    <?xml version="1.0" encoding="UTF-8"?>
    					<lead>
    					    <sender>
    					        <firstname>Marcus</firstname>
    					        <lastname>Muster</lastname>
    					        <company>Test GmbH</company>


    So is there a way to format this in the right way?

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    Shahbaaz Ansari 6,205 on at
    RE: C# read data from XML File

    Hi,

    Are you trying to use secure and unsecure config option in plugin registration tool?

    Thanks,

    Shahbaaz

  • Suggested answer
    Preeti Sharma Profile Picture
    Preeti Sharma 2,678 on at
    RE: C# read data from XML File

    Hi leon,

    Please check if you xml files contains some data.This error generally occurs when xml file is empty or does not have specific format of data

    Thanks:)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,307 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans