web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Data at the root level is invalid. Line 1, position 1

(0) ShareShare
ReportReport
Posted on by 445

Hello,

i try to read a XML file in C# but everytime i got the Error "Data at the root level is invalid. Line 1, position 1."

I dont know how to fix it. Can anyone help me?

This is my code:

                        if ((filename.ToLower() == "lead.xml" || filename.ToLower() == "lead.xml.xml") && ent.Attributes.Contains("body"))//aktualisieren
                        {
                            byte[] data = Convert.FromBase64String(ent.Attributes["body"].ToString());
                            string xml = Encoding.UTF8.GetString(data);



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

                            tracingService.Trace("läuft2");

                            foreach (XmlNode node in root)
                            {
                                if (node.Name == "recipient")
                                {...


*This post is locked for comments

I have the same question (0)
  • karthikeyani c Profile Picture
    190 on at
    RE: Data at the root level is invalid. Line 1, position 1

    Hi All,

    Can this be applied for Al code which connects Business Central ?

  • BlackBeard Profile Picture
    445 on at
    RE: Data at the root level is invalid. Line 1, position 1

    Yes!

    It works B-)

    Thank you!

  • Verified answer
    SergeyT Profile Picture
    310 on at
    RE: Data at the root level is invalid. Line 1, position 1

    Hi.

    It may be UTF BOM mark. More solutions here: stackoverflow.com/.../xml-loaddata-data-at-the-root-level-is-invalid-line-1-position-1

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans