dbnewbie
asked on
What's the point of XmlNode.InnerText
I'm curious about the purpose of Microsoft's extension to the DOM: InnerText. Take a look at the following code:
Dim a As Xml.XmlDocument = New Xml.XmlDocument
a.LoadXml("<person><name type='first'>John</name><n ame type='last'>Doe</name></pe rson>")
MessageBox.Show(a.InnerTex t)
The message box will display:
JohnDoe
Does anyone know how this might be useful? If it included a space between "John" and "Doe", there might be some use for it (e.g. tokenizing for search). But when it's concatenated this way, I'm not sure what use it is.
Also, according to http://msdn2.microsoft.com/en-us/library/system.xml.xmlnode.innertext(VS.80).aspx, this method "gets or sets the concatenated values of the node and all its child nodes." As the example shows, it only got the values of the elements and skipped the attributes. Both are "nodes." Is there a reason why the attribute nodes were excluded from the result?
Dim a As Xml.XmlDocument = New Xml.XmlDocument
a.LoadXml("<person><name type='first'>John</name><n
MessageBox.Show(a.InnerTex
The message box will display:
JohnDoe
Does anyone know how this might be useful? If it included a space between "John" and "Doe", there might be some use for it (e.g. tokenizing for search). But when it's concatenated this way, I'm not sure what use it is.
Also, according to http://msdn2.microsoft.com/en-us/library/system.xml.xmlnode.innertext(VS.80).aspx, this method "gets or sets the concatenated values of the node and all its child nodes." As the example shows, it only got the values of the elements and skipped the attributes. Both are "nodes." Is there a reason why the attribute nodes were excluded from the result?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
dbnewbie,
> I still don't get it. What can you do with JohnDoe???
If you had a space in your original XML, it would be "John Doe"
cheers
Geert
> I still don't get it. What can you do with JohnDoe???
If you had a space in your original XML, it would be "John Doe"
cheers
Geert
ASKER
That's true. But in most cases, people do not put a leading or trailing space in their element values. So, "JohnDoe" is more likely to occur than "John Doe."
This InnerText method seems totally pointless to me.
This InnerText method seems totally pointless to me.
well, this mainly usefull in mixed case elements where people do have whitespace
<text>some blabla <bold>bold </bold>some more blabla</text>
There are plenty of DOM methods I rarely use,
that doesn't necessarily mean they are pointless :-)
<text>some blabla <bold>bold </bold>some more blabla</text>
There are plenty of DOM methods I rarely use,
that doesn't necessarily mean they are pointless :-)
ASKER
Hmmm . . . so, this is designed to concatenate things that are tagged inline? I suppose this would work if the tree only branched out to one child. However, if we add another child to your sample:
<root>
<text>some blabla <bold>bold </bold>some more blabla</text>
<text>My blabla <bold>My bold </bold>My some more blabla</text>
</root>
The result would be: "some blabla bold some more blablaMy blabla My bold My some more blabla"
"blablaMy" becomes useless.
I realize the infequently used DOM methods does not mean useless. I'm just pointing this one particular method.
<root>
<text>some blabla <bold>bold </bold>some more blabla</text>
<text>My blabla <bold>My bold </bold>My some more blabla</text>
</root>
The result would be: "some blabla bold some more blablaMy blabla My bold My some more blabla"
"blablaMy" becomes useless.
I realize the infequently used DOM methods does not mean useless. I'm just pointing this one particular method.
ASKER
RE: "That can come in pretty handy sometimes (you could use it to remove all sorts of style tagging from a paragraph, or make a decent tagless string from an XML document)"
I still don't get it. What can you do with JohnDoe???