|
-
Aug 13th, 2007, 09:19 PM
#1
Thread Starter
Fanatic Member
[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!
-
Aug 14th, 2007, 08:43 AM
#2
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:
XmlDocument xd = new XmlDocument();
xd.Load(@"c:\test.xml");
XmlNode nod = xd.SelectSingleNode("/main/z:row/@ows_LinkTitle");
if (nod != null)
{
MessageBox.Show("This node has the attribute.");
}
else
{
MessageBox.Show("This node does not have the attribute.");
}
-
Aug 14th, 2007, 09:50 AM
#3
Hyperactive Member
Re: Help with XmlNode
 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
-
Aug 14th, 2007, 07:25 PM
#4
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|