checking an xml node has a perticular attribute

Last post 05-09-2008 7:34 AM by sujithukvl@gmail.com. 3 replies.

Sort Posts:

  • checking an xml node has a perticular attribute

    05-08-2008, 3:09 AM

     

    How can i check whether an xml node has a perticular attribute?

    like  

     Dim mynode As System.Xml.XmlNode =get _node()

    mynode.HasAttribute    :( we don't have this function so what to do to check this

     

     

     

     

  • Re: checking an xml node has a perticular attribute

    05-08-2008, 10:00 AM
    Answer
    • Loading...
    • SGWellens
    • Joined on 01-02-2007, 9:27 PM
    • MN, USA
    • Posts 2,286
    • Moderator
      TrustedFriends-MVPs

    You can use the Attributes property.  From the online help:

     

    using System;
    using System.IO;
    using System.Xml;
    
    public class Sample
    {
    
        public static void Main()
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5' misc='sale item'>" +
                          "<title>The Handmaid's Tale</title>" +
                          "<price>14.95</price>" +
                          "</book>");
    
            // Move to an element.
            XmlElement myElement = doc.DocumentElement;
    
            // Create an attribute collection from the element.
            XmlAttributeCollection attrColl = myElement.Attributes;
    
            // Show the collection by iterating over it.
            Console.WriteLine("Display all the attributes in the collection...");
            for (int i = 0; i < attrColl.Count; i++)
            {
                Console.Write("{0} = ", attrColl[i].Name);
                Console.Write("{0}", attrColl[i].Value);
                Console.WriteLine();
            }
    
            // Retrieve a single attribute from the collection; specifically, the
            // attribute with the name "misc".
            XmlAttribute attr = attrColl["misc"];
    
            // Retrieve the value from that attribute.
            String miscValue = attr.InnerXml;
    
            Console.WriteLine("Display the attribute information.");
            Console.WriteLine(miscValue);
    
        }
    }
     

     

    Steve Wellens
  • diffrence between Xml node and XML Element

    05-09-2008, 1:21 AM

     Xml Element has a funnction like myXmlElement.HasAttribute

    But Xml Node don't have 

     

    what is the conceptual diffrence between Xml node and XML  Element

     

     

     

  • Re: diffrence between Xml node and XML Element

    05-09-2008, 7:34 AM
    Answer

    http://www.dotnet247.com/247reference/msgs/5/29254.aspx 

Page 1 of 1 (4 items)