This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > August 2005 > Convert XmlNode into XmlElement





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Convert XmlNode into XmlElement
Luca

2005-08-22, 7:16 am

Hi

I am quiet new using XML classes in C# and I have tried many things.
I am using a webservice which gaves back a XmlNode but my object, which
should use the data needs a XmlElement.

I thought his would be right:
XmlElement myXmlElement = myXmlNode as XmlElement;

But it doesnt work.
Thx
Martin Honnen

2005-08-22, 7:31 pm



Luca wrote:


> I thought his would be right:
> XmlElement myXmlElement = myXmlNode as XmlElement;


You can only cast the XmlNode to an XmlElement if the NodeType is 1, it
is not possible to cast anything into an element.
So your code is the correct approach but you only get an XmlElement if
the cast is possible so you need to check
if (myXmlElement != null) {
// now use myXmlElement here
}
after your statement.
If you need more help then we need to see your XML and then you need to
explain exactly what you expect that cast to do if myXmlNode is not an
element node.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews