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

Announcements

News and Announcements icon
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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans