开发者

How to know when to cast to an Xelement or XAttribute?

I have a situation where 开发者_如何学Pythonan 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 ?


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜