What is the return of System.Xml.XmlNode.ParentNode supposed to be

A

Andrew Falanga

Hi,

I'm writing a routine to find a child node in an XML file that
basically walks the tree until the <tag></tag> is found. In learning
how to use the routines in System.Xml, I'm working in a sandbox. Now,
the search function I have written does work to find the node now.
The question is, as I'm trying to understand better what it is I'm
looking at, I'm dumping some of the properties to stdout. Something
that struck me odd is that the ParentNode property of the XmlNode
where my child was found, doesn't print the parent node but something
else. For example,

<SimpleXmlDoc>
<Example>
<Child1>
</Child1>
</Example>
</SimpleXmlDoc>

Now, I'm looking for Child1, which is found, but when I print out that
XmlNode's ParentNode property, I'm returned, "System.Xml.Element"
instead of, "Example." This is not what I was expecting.

Using the Object Browser in VS, the return, for an element node,
should be the parent XML (in this case, Example). From the object
browser:

"Element Returns the parent node of the element. If the element is the
root node in the tree, the parent is the document node."

So, what am I not understanding?

Andy
 
P

Peter Duniho

Andrew said:
[...]
<SimpleXmlDoc>
<Example>
<Child1>
</Child1>
</Example>
</SimpleXmlDoc>

Now, I'm looking for Child1, which is found, but when I print out that
XmlNode's ParentNode property, I'm returned, "System.Xml.Element"
instead of, "Example." This is not what I was expecting.

Are you sure it displays "System.Xml.Element" and not
"System.Xml.XmlElement"?
Using the Object Browser in VS, the return, for an element node,
should be the parent XML (in this case, Example). From the object
browser:

"Element Returns the parent node of the element. If the element is the
root node in the tree, the parent is the document node."

So, what am I not understanding?

As near as I can tell, mainly you're misunderstanding what the output in
the debugger of a property value is. The debugger simply calls the
ToString() method of the object. But for many types (including
System.Xml.XmlElement), the ToString() is not overridden and simply
returns the name of the type of the object.

If you were to examine some specific property of the object in which you
would expect to see the content or element name you expect, (e.g. the
LocalName property), then you should see the text "Example" (for example).

Pete
 
A

Andrew Falanga

Andrew said:
[...]
<SimpleXmlDoc>
   <Example>
      <Child1>
      </Child1>
   </Example>
</SimpleXmlDoc>
Now, I'm looking for Child1, which is found, but when I print out that
XmlNode's ParentNode property, I'm returned, "System.Xml.Element"
instead of, "Example."  This is not what I was expecting.

Are you sure it displays "System.Xml.Element" and not
"System.Xml.XmlElement"?

Yes, it is saying that. I can't believe I left that out when typing
the post. I was looking at the output while typing.
As near as I can tell, mainly you're misunderstanding what the output in
the debugger of a property value is.  The debugger simply calls the
ToString() method of the object.  But for many types (including
System.Xml.XmlElement), the ToString() is not overridden and simply
returns the name of the type of the object.

If you were to examine some specific property of the object in which you
would expect to see the content or element name you expect, (e.g. the
LocalName property), then you should see the text "Example" (for example)..

Pete

I'm not sure I follow you here. I'm outputting the value of
System.Xml.XmlNode.ParentNode (the Parent Node property of the XmlNode
class). I thought that this would contain the text I'm looking for
(in the example above, the string "Example").

Andy
 
P

Peter Duniho

Andrew said:
[...]
As near as I can tell, mainly you're misunderstanding what the output in
the debugger of a property value is. The debugger simply calls the
ToString() method of the object. But for many types (including
System.Xml.XmlElement), the ToString() is not overridden and simply
returns the name of the type of the object.

If you were to examine some specific property of the object in which you
would expect to see the content or element name you expect, (e.g. the
LocalName property), then you should see the text "Example" (for example)..

Pete

I'm not sure I follow you here. I'm outputting the value of
System.Xml.XmlNode.ParentNode (the Parent Node property of the XmlNode
class). I thought that this would contain the text I'm looking for
(in the example above, the string "Example").

I feel confident my explanation applies and should suffice. However, if
you need further elaboration, you're going to have to ask a more
specific question. The phrase "I'm outputting the value of
System.Xml.XmlNode.ParentNode" isn't very clear with respect to what
you're actually doing.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top