ServerXMLHTTP and nodeValue versus nodeTypedValue

A

Adam David Moss

All,

Long time since I've done some proper coding in ASP and I've hit a wee snag
that has got me baffled. Well two actually but the other is to do with
running pages under Sun ASP so we'll not go there! Anyway, I digress...

I've cobbled together some code as shown below (removed error checking etc
for simplicity). This uses ServerXMLHTTP to grab an XML file off a remote
server. When querying the result, however, the nodeValue property is null
whereas the nodeTypedValue property isn't.

Can anyone please advise as this I would expect nodeValue to be populated.

Cheers,


Adam M.

===== BEGIN_TESTPAGE.ASP ====
<%
Dim objXMLHTTP

Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")

With objXMLHTTP
.open "GET", "http://www.myserver.eu/test.asp", False
.send

Response.Write "Status: " & .status & "<br />"
Response.Write "Parse:" & .responseXML.parseError.errorCode & "<br />"

Response.Write
..responseXML.documentElement.childNodes(0).childNodes(0).nodeTypedValue
Response.Write
..responseXML.documentElement.childNodes(0).childNodes(0).nodeValue
End With

Set objXMLHTTP = Nothing
%>
===== END_TESTPAGE.ASP =====

===== BEGIN_TEST.ASP =====
<% Option Explicit

With Response
.Buffer = True

.AddHeader "Pragma", "no-cache"

.CacheControl = "no-cache"

.Expires = -1

.ContentType = "text/xml"

.Charset = "UTF-8"
End With %><?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<tLRecords>
<tLRecord>
<tL>A</tL>
<tLD>B</tLD>
<tLED>2008-06-24</tLED>
<rL>C</rL>
<rLD>D</rLD>
</tLRecord>
</tLRecords>
===== END_TEST.ASP =====
 
M

Martin Honnen

Adam said:
Long time since I've done some proper coding in ASP and I've hit a wee
snag that has got me baffled. Well two actually but the other is to do
with running pages under Sun ASP so we'll not go there! Anyway, I
digress...

I've cobbled together some code as shown below (removed error checking
etc for simplicity). This uses ServerXMLHTTP to grab an XML file off a
remote server. When querying the result, however, the nodeValue
property is null whereas the nodeTypedValue property isn't.

Can anyone please advise as this I would expect nodeValue to be populated.

The nodeValue of element nodes in the DOM model is always null. With
MSXML there is property named 'text' which gives you the text content of
a node so in case of an element
<tL>A</tL>
to text property is "A".
 
A

Adam David Moss

That's got me confused - I have other bits of code that define objects of
type MSXML.DOMDocument and the nodeValue works as expected?

Regards.
 
A

Anthony Jones

Adam David Moss said:
That's got me confused - I have other bits of code that define objects of
type MSXML.DOMDocument and the nodeValue works as expected?

nodeValue and nodeTypedValue despite appearances are very different
properties.


nodeValue is a standard DOM property which returns a nodes value. Node
types such as an attribute or a text node have a value. Elements however do
not have a value they only have child nodes of various types.

Hence in your original code you could include this line:-

Response.Write
..responseXML.documentElement.firstChild.firstChild.firstChild.nodeValue

and it would return a value. Whilst a simple XML element that only contains
text may appear that it should have the value of its text it is infact an
element that has a single child node. The child node is a text node and its
the text node that has a value.



OTH nodeTypedValue is an MS enhancement which allows a simple element to
carry a value which may be typed. The element may carry a dt:dt attribute
(where dt is alias for the "urn:schemas-microsoft-com:datatypes" namespace)
that defines a data type. The nodeTypedValue returns a variant with a VT
type corresponding to the dt:dt attribute. If dt:dt is not present string
is assumed. The value of the property is drawn from the text of the
element.


Hope this clarifies things.
 
M

Martin Honnen

Adam said:
That's got me confused - I have other bits of code that define objects
of type MSXML.DOMDocument and the nodeValue works as expected?

Well nodeValue makes sense for text nodes, cdata section nodes,
attribute nodes, comment nodes, processing instruction nodes. The
"expected" value however for element nodes or document nodes is null
(respectively Nothing in VBScript), see
http://msdn.microsoft.com/en-us/library/ms756022(VS.85).aspx
which lists what nodeValue gives for the different types of nodes.
 
A

Anthony Jones

Martin Honnen said:
The "expected" value however for element nodes or document nodes is null
(respectively Nothing in VBScript),

Getting a little .NET parlance mixed in there ;)

Its Null in VBScript also (nodeValue returns a variant).
 
M

Martin Honnen

Anthony said:
Getting a little .NET parlance mixed in there ;)

Its Null in VBScript also (nodeValue returns a variant).

Thanks for correcting. It seems .NET has spoiled the few VBScript
experiences I ever had.
 
A

Adam David Moss

Thanks guys that makes sense now!

Cheers.




Martin Honnen said:
Thanks for correcting. It seems .NET has spoiled the few VBScript
experiences I ever had.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top