You must Sign In to post a response.
  • Category: XML

    How to check that XML is valid XML ?

    Hello All,

    I am working on project,
    In this project i am generating one xml file using one xslt and want to send this xml to StringReader but it's not ? and after sending it to StringReader out put is Noting. i want to check that the XML i m passing to it is valid.
    Can some one tell me how to check that ?

    Nilesh Thakur.
  • #746518
    You need to use XMLDocument object in which XML is parse while loading.
    see below snippet

    XMLDocument objDom;
    objDom = new XMLDocument();
    objDom.LoadXml("xml string");
    Catch (Exception ex)
    //error occurred while parsing xml
    string szError = ex.Message;
    objDom = null;

    hope it helps

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #746519
    Open the XML in IE if the file is opened then there is no error other wise it will show the error.

    You can also make use of the XML document object in code to check.

    if the Object is loaded there will not be error other wise you will get the error.

    XMLDocument xDoc = new XMLDocument("Ur file Name here);

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #746539
    Hai Nileash,
    To validate your XML, first you need to generate the Schema Definition(XSD) for your XML.
    Once you have the XSD, you can easily validate each of the node which is generated in your XML document.
    Please find the below article to generate the schema definition and then validate the incoming XML:

    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • Sign In to post your comments