Skip to main content
武中40993157
Participant
February 22, 2018
Question

return value of xml object length function doesn't show in databrowser instead showing xml object

  • February 22, 2018
  • 3 replies
  • 459 views

Is this a bug or am I completely taking something wrong?

I am using ESTK CS5.

I am a beginner of ESTK, so pls kindly give me an advice.

Regards,

Take

This topic has been closed for replies.

3 replies

武中40993157
Participant
February 26, 2018

Thank you Mark,

XML file imported myXML object does't contain <length> tag but it appears in data browser as it does so, still looks strange to me.

But somehow I've got idea what's going on by you.

Thank you Dirk,

I looked into the script. It might be userful to me.

Legend
February 24, 2018

While the technical reasons are now understood, that does not change the actual problem of the data browser display. In the ESTK SDK sample scripts I recently have found a generic XML browser that might be useful as a starting point for an own approach. Watch out for a file called "SnpXMLTreeView.jsx" ...

Regards,

Dirk

Loic.Aigon
Legend
February 22, 2018

Not a bug at all. Length isn't a property but a XML object itself. You need to use () to retrieve the current value as in :

myNodes.length() //=> n

武中40993157
Participant
February 23, 2018

Thanks Loic.Aigon-san,

If those functions are properties, those values shows in data browser conviniently like it does in VB ,Java or C language.

Is it the difference of script or compile language so the script execution can speed up or anything?

And I coundn't complety understand the part you mentioned length is the XML object itself. What do you mean exactly by that?

Regards,

Take

Marc Autret
Legend
February 23, 2018

Hi Take,

What Loïc meant—I guess—is that length is not a regular property of an XML instance, since XML.prototype has no properties at all (it only has methods.) The reason is syntactic: any myXML.foobar syntax is interpreted in a way that makes it refer to an XML child of myXML. This remains true even if foobar is not an actual child of the XML structure. Therefore, myXML.length is syntactically an XML instance (and more accurately, an XMLList instance.)

And here is a case it could have actual data:

var myXML = <root><length>hello</length></root>;

alert( myXML.length ); // => hello

Apart from that—and as a purely homonymic fact—it turns out that length() is a method of both XML.prototype and XMLList.prototype, as specified in ECMA-357: https://www.ecma-international.org/publications/files/ECMA-ST-WITHDRAWN/Ecma-357.pdf#page=94

Note that there is no connection between myXML.length and myXML.length(). The latter will return an integer. For example, in the above example, we have myXML.length.length()==1 ;-)

@+

Marc