Groups | Blog | Home
all groups > dotnet xml > september 2003 >

dotnet xml : XmlNode.Value


Eirik M.
9/25/2003 3:27:55 PM
Can anyone from M$ or anyone else for that matter explain to me the
reasoning behind the intended usage for this property? I was quite surprised
to find that this property may be null depending on the XmlNodeType. If one
imagines a scenario where some hapless programmer adds a new node to an
XML-document, e.g.

childNode = doc.CreateNode (XmlNodeType.Element, "foo", "");

and then decides to set the *value* (the "string" between <nodename> and
</nodename>) of this node, one could easily imagine that our programmer
would look for a method or property called setValue/setNodeValue or just
Value. Unfortunately, setting this value will cause an exception if the node
is an XmlElement. Instead our programmer is supposed to use a property
called 'InnetText'! How intuitive is that? IMHO the designers of the XmlNode
class has got this wrong, especially with respect to the use of the terms
Value (for something that clearly isn't) and InnerText and the former's more
or less hidden dependency on XmlNodeType.

Opinions, anyone?

Eirik M.

Eirik M.
9/25/2003 4:46:24 PM

[quoted text, click to view]

:-)

[quoted text, click to view]
http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-core.html#ID-1950641247

Ok. I was afraid this was the case. You see Oleg, I've just written a Java
client to access a set of web-services and I used GLUE as the Xml library
and there I can do node.getNodeValue () and node.setNodeValue ("some
value"). For elements I can call element.SetInt for Ints, element.SetText
("") for string values, etc. So I sort of expected something similar in
..Net.

[quoted text, click to view]

I see that now.

[quoted text, click to view]

Too late. However, nothing stops implementers from abstracting the spec to
make it more useable :-)

Eirik M.

[quoted text, click to view]

Oleg Tkachenko
9/25/2003 5:04:38 PM
[quoted text, click to view]

Well, when working with DOM for years, it looks intuitive enough :)
Otherwise - I'm agree that's not too clear for a newbie.

As a matter of fact it's how DOM standard was designed - elements and some
other nodes have no value.
See
http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-core.html#ID-1950641247

[quoted text, click to view]

They just implemented W3C DOM standard. Send your objections to W3C instead.

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
AddThis Social Bookmark Button