Results 1 to 4 of 4

Thread: [RESOLVED] Help with XmlNode

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Resolved [RESOLVED] Help with XmlNode

    hi guys! Help please..I have XmlNode named rowNode and it has value
    <z:row
    ows_fRecurrence=\"0\"
    ows_LinkTitle=\"BAC Meeting\"
    ows_EventDate=\"2007-08-14 08:30:00\"
    ows_Location=\"rghergrege\"
    ows_Alarm=\"2007-08-14 08:25:00\"
    ows_AlarmMemberChoice=\"ALL\"
    ows_Attachments=\"0\"
    ows_Attachment=\", \"
    ows_Title=\"BAC Meeting\"
    ows_ID=\"105\"
    ows_owshiddenversion=\"4\"

    xmlns:z=\"#RowsetSchema\" />"
    but sometime it can have value like this
    <z:row
    ows_fRecurrence=\"0\"
    ows_LinkTitle=\"BAC Meeting\"
    ows_EventDate=\"2007-08-14 08:30:00\"
    ows_Alarm=\"2007-08-14 08:25:00\"
    ows_AlarmMemberChoice=\"ALL\"
    ows_Attachments=\"0\"
    ows_Attachment=\", \"
    ows_Title=\"BAC Meeting\"
    ows_ID=\"105\"
    ows_owshiddenversion=\"5\"
    xmlns:z=\"#RowsetSchema\" />"
    notice that "ows_Location" in the second value does not exist. My question is how will check if "ows_Location" exist in the value? Thanks in advance!

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: Help with XmlNode

    XPath to the rescue! You can check your node to see if it contains that attribute quite easily with the correct XPath.

    c# Code:
    1. XmlDocument xd = new XmlDocument();
    2. xd.Load(@"c:\test.xml");
    3.  
    4. XmlNode nod = xd.SelectSingleNode("/main/z:row/@ows_LinkTitle");
    5.  
    6. if (nod != null)
    7. {
    8.     MessageBox.Show("This node has the attribute.");
    9. }
    10. else
    11. {
    12.     MessageBox.Show("This node does not have the attribute.");
    13. }

  3. #3
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502

    Re: Help with XmlNode

    Quote Originally Posted by daimous
    hi guys! Help please..I have XmlNode named rowNode ...
    If you already have an instance of the XmlNode, then it can be done really easy. (XmlNode itself is an abstract class, so I assume it's an XmlElement instance you have, which inherits from the XmlNode class.)

    Code:
    XmlElement node = ... ; //you already have this one I assume
    XmlAttribute attribute = node.Attributes["ows_Location"];
    bool attributeExists = (attribute != null);
    If you don't have an XmlElement after all then, you just need to cast it first, probably.

    Code:
    XmlNode someXmlNode = ...; //you had this one already
    XmlElement node = (XmlElement)someXmlNode;
    I hope this is the answer you expected. Good luck with your projects either way!
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

  4. #4

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Help with XmlNode

    THanks a lot guys! It really helps me a lot..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width