views:

36

answers:

1

I have a situation where an end user can enter an XPath to access a value in some XML. I’m using a line of code similar to the one below:

IEnumerable e = (IEnumerable)importDocument.XPathEvaluate(theXPath);

As the Xpath could return an Attribute or an Element, what I need to know is how can I interpret ‘e’ in the above example to decide to cast to an XElement or XAttribute ?

+2  A: 

Something like?

XElement element = e.Current as XElement;
XAttribute attrib = e.Current as XAttribute;

if(element != null)
   //Is Element, use element
else
   //Is Attribute, use attrib

Or do you want to cast the Enumerator?

Binary Worrier
Thanks, this is similar to what I was doing.
Retrocoder