NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

.Net XmlNodeList.Item() returns the wrong object type

I'm trying to iterate through nodes in an xml file using .Net System.Xml classes. I create an XmlDocument object, load a file, get the Child nodes (which go into a an XmlNodeList). From there, you should be able to call the .Item(int index) method of the XmlNodeList and get an XmlNode object back. But, the call instead returns an XmlDeclaration object. Has anyone else seen this? Is this a bug in the TestStand implementation of the System.Xml classes?

0 Kudos
Message 1 of 4
(4,585 Views)

@JohnW242424 wrote:

I'm trying to iterate through nodes in an xml file using .Net System.Xml classes. I create an XmlDocument object, load a file, get the Child nodes (which go into a an XmlNodeList). From there, you should be able to call the .Item(int index) method of the XmlNodeList and get an XmlNode object back. But, the call instead returns an XmlDeclaration object. Has anyone else seen this? Is this a bug in the TestStand implementation of the System.Xml classes?


1) XmlDeclaration is derived from XmlNode: https://msdn.microsoft.com/en-us/library/system.xml.xmldeclaration%28v=vs.110%29.aspx

Thus you can use that object anywhere where you can also use an XmlNode. You can even select the XmlNode class in the .NET adapter and give it that object as the existing object to make the call on. The TestStand variables view is just showing you the most derived class for the object.

 

2) TestStand does not implement System.Xml classes, when you use the .NET adapter to call these APIs you are calling into the Micrososft .NET framework libraries directly.

 

Hope this helps,

-Doug

0 Kudos
Message 2 of 4
(4,566 Views)

Doug,

   Thanks for the reply. I know I am calling the .Net libraries directly...at least that is what I thought.

Yes, the way I worded my question was not very clear.

'TestStand implementation of the System.Xml classes' was not the correct way to phrase it.

Maybe saying 'the wayTestStand facilitates calls to .Net modules.. is more accurate?

 

Anyway, the root of my question is:

 

When I call the XmlNodeList.Item() method in C# or VB.Net code, I always get an XmlNode object in return, as the Microsft documentation says I should.

Yet, when I call the same method, with the same parameter from TestStand, I get an XmlDeclaration object...not what is expected.

 

Clearly there is something in the way TestStand is facilitating calls to .Net modules that is causing this difference.

 

Like you said, maybe it is immaterial as I can still extract the info I need from the XmlDeclaration.

Just makes one wonder, 'Is there something else going on under the hood?'

0 Kudos
Message 3 of 4
(4,560 Views)

When I call the XmlNodeList.Item() method in C# or VB.Net code, I always get an XmlNode object in return, as the Microsft documentation says I should.

Yet, when I call the same method, with the same parameter from TestStand, I get an XmlDeclaration object...not what is expected.

 


Even when you call Item() in C# and VB.Net you are still getting an object that is an XmlDeclaration in this case, you are just accessing it via its base class of XmlNode. That doesn't change the fact that it was created as an XmlDeclaration object. You can verify this as follows in C#:

 

// myObjAsXmlDeclaration  will not be null if myObjReturnedFromItem is really an XmlDeclaration.

XmlDeclaration myObjAsXmlDeclaration = myObjReturnedFromItem as XmlDeclaration;

 

Effectively all the variables view in teststand is doing is:

 

string mytypename = myObjReturnedFromItem.GetType().ToString();

 

The way class derivation works is that an object can be accessed as if it was any of its base classes, but that doesn't change the fact that it is really an instance of its most derived class as well. The only thing TestStand is doing differently is that the type it shows in the variables view is the most dervived type of the object and not necessarily the return type the method had that you got the object from.

 

Hope this helps clarify things,

-Doug

0 Kudos
Message 4 of 4
(4,553 Views)