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)

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)
  • Verified answer
    SergeyT Profile Picture
    310 on at

    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

  • BlackBeard Profile Picture
    445 on at

    Yes!

    It works B-)

    Thank you!

  • karthikeyani c Profile Picture
    190 on at

    Hi All,

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

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