Opened 2 years ago

Closed 13 months ago

#15176 closed defect (wontfix)

[CLA] [PATCH] _getXPath used for dojox.data.XmlStore identity uses 0-based index instead of 1

Reported by: suns Owned by: kzyp
Priority: undecided Milestone: tbd
Component: DojoX Data Version: 1.6.1
Keywords: Cc: jaredj
Blocked by: Blocking:

Description

_getXPath returns unique string which is serving good as identity but could not be used for XML navigation.

/root[0]

is not a valid XPath expression. XPath assumes 1-based indexes:

/root[1]

stands for first element.

Patch is simple setting "1" instead of "0" in

                        while(node && node != element.ownerDocument){
                                var pos = 1;// XPath uses 1-based indexes
                                var sibling = node;
                                var name = node.nodeName;
                                while(sibling){
                                        sibling = sibling.previousSibling;
                                        if(sibling && sibling.nodeName === name){
                                                pos++;
                                        }
                                }
                                var temp = "/" + name + "[" + pos + "]";

Patch does not change the identity functionality but adds XPath capabilities.

Attachments (2)

XmlStore.js.patch (407 bytes) - added by suns 2 years ago.
XPath index base set to 1
XmlStore-identity-XPath.patch (5.1 KB) - added by suns 2 years ago.
XPath index base set to 1

Download all attachments as: .zip

Change History (7)

comment:1 Changed 2 years ago by ktiedt

  • Component changed from General to DojoX Data
  • Owner set to kzyp
  • Summary changed from _getXPath used for dojox.data.XmlStore identity uses 0-based index instead of 1 to [CLA] [PATCH] _getXPath used for dojox.data.XmlStore identity uses 0-based index instead of 1

Changed 2 years ago by suns

XPath index base set to 1

Changed 2 years ago by suns

XPath index base set to 1

comment:2 Changed 2 years ago by suns

Second attachment( XmlStore-identity-XPath.patch ) has a source and test patch for 1.6 with tests passed. Change is browser agnostic, but tested under IE9, current FF and Chrome.

comment:3 Changed 2 years ago by bill

  • Cc jaredj added

Oh, so you are saying that not only was there an error in the code, but there were also errors in the test file. I haven't used XPATH for a number of years but I checked http://www.w3schools.com/xpath/xpath_syntax.asp and it confirms that the indexes start at one, although it also says that IE starts them at 0, so I'm not sure if the current code starts at 0 intentionally or by accident.

comment:4 Changed 2 years ago by suns

w3schools sometimes mistaken. XPath was well supported by MSXML from IE5 in very W3C compliant way.
http://msdn.microsoft.com/en-us/library/ms256086.aspx

The initial use of identity has been created with XPath-like notion but does not match XPath itself. In patch semantics of identity was not changed. Tests for some reason do not reflect identity meaning. Instead of comparing entry referenced by id string, test are comparing strings themselves.
The right way would be replace tests with id-agnostic ones.
I am working on dojox.store.XmlStore creation. Perhaps it will make this module( dojox.data.XmlStore) outdated. Tests for identity could be common for both modules. I am not convinced current identity concept is right in general.

Last edited 2 years ago by suns (previous) (diff)

comment:5 Changed 13 months ago by csnover

  • Resolution set to wontfix
  • Status changed from new to closed

dojox/data is abandoned. Some dojox/data stores have been upgraded to use the Dojo Store API and can be found at https://github.com/kfranqueiro/dojo-smore.

Note: See TracTickets for help on using tickets.