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 AX (Archived)

error while reading xml file

(0) ShareShare
ReportReport
Posted on by

XmlDocument doc = new XMLDocument();
    XmlParseError x ;
    XmlElement m;
    XmlNodeList l;
    int i;
    XmlElement xmlRecord;
    XmlNodeList xmlRecordList;

    doc.loadXml("D:\Eclipse\BSRIntMexInvtAdjReqStagingService\BSRIntMexInvtAdjReqStaging.xml");

    x = doc.parseError();

this code giving me error:

NAME:
    x
VALUE:
    System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
   at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at System.Xml.XmlDocument.LoadXml(String xml)
   at DotNet.XmlDocument.LoadXml(XmlDocument* , Char* xml, Boolean trapError)
TYPE:
    XmlParseError

Could anyone suggest me whats problem with this code/xml file?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    Hi Aniket_Nimbekar,

    loadXml() method loads XML from a string and "D:\Eclipse\BSRIntMexInvtAdjReqStagingService\BSRIntMexInvtAdjReqStaging.xml" is not a valid xml string. To load XML from file use load() instead.

  • Community Member Profile Picture
    on at

    Hi,

    But I wanted to achieve this using loadxml(). I know using load() will solve my problem. Can you tell me what kind of changes  that i have to made to solve this error using loadxml()?

  • Mea_ Profile Picture
    60,284 on at

    you need to read file to a string (using TextIo for instance) and then pass this string to a file. But why do you need that ?

  • Community Member Profile Picture
    on at

    Because it was previously mentioned to use loadxml(). Can you please provide me sample code for it?

  • Mea_ Profile Picture
    60,284 on at

    Could you please create new thread for new question ? This thread was about "System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1." error. Now you asking how to read a file into a string, that has nothing related to original question. It's hard to follow threads with multiple questions, so please keep them separated.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    The documentation clearly says that it is expecting a str variable which contains the XML in plain text, and not a file name.

    [View:https://msdn.microsoft.com/en-us/library/xmldocument.loadxml.aspx:750:50]

    It takes 1 minute to find examples on how to read in file contents within AX, please use a search engine:

    [View:http://lmgtfy.com/?q=ax+read+file:750:50]

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 AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans