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

    Need to read xml tag in c#

    Hi All,

    <CogonsAdmin>
    <Schema Name="Public Schema">
    <Access Name="None" />
    <Access Name="Basic Access" />
    <Access Name="Intermediate Access" />
    <Access Name="Super Admin" />
    </Schema>
    <Schema Name="Prelim Schema">
    <Access Name="None" />
    <Access Name="Basic Access" />
    <Access Name="Intermediate Access" />
    <Access Name="Super Admin" />
    </Schema>
    </CogonsAdmin>

    howcan i read the above xml in c#.
    My output should be
    Public Schema
    ==========
    None
    Basic Access
    Intermediate Access
    Super Admin

    Prelim Schema
    ==========
    None
    Basic Access
    Intermediate Access
    Super Admin

    It should be list in ablove format..


    Regards,
    Saravana
  • #765286
    It is simple you can use XMLReader or XMLDocument to read xml
    see below snippet where I have read xml file using XMLDocument class

    using System.XML

    XmlDocument Dom = new XMLDocument();
    Dom.Load(//filepath);
    //read particular tag
    XMLNodeList xnList = Dom.getElementById("Schema");
    for each(XMLNode XN in xnList )
    {
    //write attributes of scemaTag that is Public and Prelim scema
    console.writeLine( XN.Attributes['0"].value)
    // Loop on each child of schema
    for each (XMLNode XNChild in XN.childNodes)
    {
    //write attributes of Access
    console.writeLine( XNChild.Attributes['0"].value)
    }
    }

    hope it helps

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

  • #765507
    there are so many ways we can do it.
    Xmldocument, XmlNavigator,XmlPathsector like this . Please search in google with these or see the below Uniform resource locator.
    http://www.dotnetspider.com/resources/45564-Navigation-through-Xml-Elements.aspx

    SRI RAMA PHANI BHUSHAN KAMBHAMPATI


Sign In to post your comments