reading xml "attribute name"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • libish
    New Member
    • Oct 2008
    • 42

    reading xml "attribute name"

    hi all..
    can any one help me by suggesting an idea to take the attribute "name" from a node.

    <r t="error" a="active" i="">
    here t , a , i are the attribute name
    and
    "error" , "active" , "" are the values.

    here "r" is the node and t="error" ,a="active" , i="" are the attributes...

    here i kno how to get the values of the attributes t,a and i.

    but what i need is to read the name of attributes ie t,a and i. can any one suggest.
    thanks in advance.
  • markmcgookin
    Recognized Expert Contributor
    • Dec 2006
    • 648

    #2
    Originally posted by libish
    hi all..
    can any one help me by suggesting an idea to take the attribute "name" from a node.

    <r t="error" a="active" i="">
    here t , a , i are the attribute name
    and
    "error" , "active" , "" are the values.

    here "r" is the node and t="error" ,a="active" , i="" are the attributes...

    here i kno how to get the values of the attributes t,a and i.

    but what i need is to read the name of attributes ie t,a and i. can any one suggest.
    thanks in advance.
    Is this in .Net?

    Try:

    Code:
    foreach(XMLAttribute att in r.Attributes)
    {
        if (att.Name == "a")
        {
            //do something
        }
    }

    Comment

    • libish
      New Member
      • Oct 2008
      • 42

      #3
      Originally posted by markmcgookin
      Is this in .Net?

      Try:

      Code:
      foreach(XMLAttribute att in r.Attributes)
      {
          if (att.Name == "a")
          {
              //do something
          }
      }

      yes this is in c#.net...
      what does "r" stands for
      i tried XmlTextReader "reader.Attribu tes" but there is no such option available..
      can u please specify little bit more..

      Comment

      • markmcgookin
        Recognized Expert Contributor
        • Dec 2006
        • 648

        #4
        Originally posted by libish
        yes this is in c#.net...
        what does "r" stands for
        i tried XmlTextReader "reader.Attribu tes" but there is no such option available..
        can u please specify little bit more..
        r is the name of the xmlnode, so r.attributes would contain a list of all the attributes associated with that node.

        Code:
        xmldocument xmldoc = new xmldocument();
        xmldoc.load(xmlpath);
        xmlnodelist nl = xmldoc.getelementsbytagname("r");
        or something to that effect should return a list of nodes with the name "r" that you could loop through and process.

        Mark

        Comment

        Working...