user1981665
user1981665

Reputation:

Purpose of this code (XmlElement)XmlDocument

I'm working on a web service API for one of our customers. I've never touched this code before and the original developer is no longer with the company.

      XmlDocument xDoc = new XmlDocument();
      xDoc.LoadXml(xmlReply);

      XmlElement element = (XmlElement)xDoc.GetElementsByTagName('TagName')[0];

What is the purpose of the XmlElement class name inside the parentheses?

Upvotes: 1

Views: 73

Answers (2)

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236268

This is a casting. GetElementsByTagName returns XmlNodeList, which have items of type XmlNode. XmlNode is a base class of XmlElement and need to cast it to XmlElement.

Upvotes: 1

marteljn
marteljn

Reputation: 6516

This is a simple casting operation. The point of this is to cast the result of the method call to the type XmlElement.

http://msdn.microsoft.com/en-us/library/ms173105.aspx

Upvotes: 1

Related Questions