Help Parsing XML in C Sharp

Experts,
 I am TRYING to do something, supposibly simple in C#, which i know how to do in ASP.NET
Please Help

I have the code for both form data and Code behind

I simple want to pass the Path of the XML to the Function and have it display data

HELP PLEASE


//--------------------Form
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ssrf._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <%
                 string xmlPath="c:\itt\7763V.xml";  
                ProcessXml(xmlPath); 
     %>
    </div>
    </form>
</body>
</html>
//-------------------Code Behind--------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace ssrf
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             
        }


        private void ProcessXml(string xmlPath)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(xmlPath);

            // Set up namespace manager for XPath    
            XmlNamespaceManager nsMgr = new XmlNamespaceManager(doc.NameTable);



            nsMgr.AddNamespace("ddms", "urn:us:gov:dod:standard:ssrf:1.2.4.b");
            nsMgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
            nsMgr.AddNamespace("s", "urn:us:gov:dod:standard:ssrf:1.2.4.b");
            nsMgr.AddNamespace("my", "http://metadata.dod.mil/mdr/ns/SSRF/1.2.4.b/ssrf.xsd");


            XmlNodeList txrx2 = doc.SelectNodes("s:SSRF/s:Body/s:TxRx", nsMgr);

            foreach (XmlNode node in txrx2)
            {
                WalkNodes(node);
            }
        }

        private void WalkNodes(XmlNode iXmlNode)
        {
            if (iXmlNode.InnerText != null)
            {
                Response.Write("Element - " + iXmlNode.Name + ": " + iXmlNode.InnerText + "<br>");
            }
            Response.Write(iXmlNode.InnerXml);
            if (iXmlNode.Attributes != null)
            {
                if (iXmlNode.Attributes.Count > 0)
                {
                    Response.Write(iXmlNode.Name + " Attributes: " + "<br>");
                    int Atcount;
                    //Atcount = (iXmlNode.Attributes.Count - 1);
                    //for (int atrib = 0;Atcount;atrib++) //<---- error i get is - Cannot convert type 'int' to 'bool'
                    //{
                    //    Response.Write("     " + iXmlNode.Attributes(atrib).Name + " - " + iXmlNode.Attributes(atrib).Value + "<br>");
                    //error i get is - System.XML.XMLNode.Attributes is a 'property' but used like a 'method'
                    // } 


                    // Get the node's attributes
                    XmlAttributeCollection attCol = iXmlNode.Attributes;

                    // Print them for testing
                    Response.Write(attCol[0].Value + "<br/>");

                }
            }

            foreach (XmlNode child in iXmlNode.ChildNodes)
            {
                WalkNodes(child);
            }


        } 
           

    }
}

Open in new window

ssrf2.zip
LVL 1
dsiemonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
What version of ASP.NET do you have?  You might be able to use an XmlDataSource...
0
AshokSr. Software EngineerCommented:
Atcount = (iXmlNode.Attributes.Count - 1);
                   
for (int atrib = 0;atrib <= Atcount;atrib++) //<---- error i get is - Cannot convert type 'int' to 'bool'
{
  Response.Write("     " + iXmlNode.Attributes(atrib).Name + " - " + iXmlNode.Attributes(atrib).Value + "<br>");
}

HTH
Ashok
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anarki_jimbelSenior DeveloperCommented:
OK, I believe  you need to use square brackets to supply index for attributes:

 iXmlNode.Attributes[atrib].Name

ashok111 has fixed another error, I hope
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.