web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Suggested answer
    Preeti Sharma Profile Picture
    2,678 on at

    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:)

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at

    Hi,

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

    Thanks,

    Shahbaaz

  • BlackBeard Profile Picture
    445 on at

    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
    gdas Profile Picture
    50,091 Moderator on at

    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
    445 on at

    Hi Goutam,

    i allready have this in my code...

    But it dont works... -.-

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans