Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

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

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

  • karthikeyani c Profile Picture
    karthikeyani c 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
    BlackBeard 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
    SergeyT 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,188 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,030 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans