Insert position of attributes

Friday, 2 December 2011 · 4 messages · last reply 4 Dec 2011
DG
Dave Glick2 Dec 2011 19:36 #
How would one go about inserting an attribute at a specific position (i.e., somewhere other than at the front of the attribute list)? I would expect the following expression would do the trick: "insert node attribute aname {'avalue'} as last into //XYZ" but it still inserts the attribute at the front of the attribute list. By looking at the code in the InsertAttribute update primitive, I can see that it's hardcoded to insert at the front of the attribute list. Does this mean that there is no way to control attribute insertion location? Does the XQuery Update standard not allow such an update or is this a bug/oversight on the part of BaseX? Thanks! Dave
DG
Dave Glick2 Dec 2011 19:46 #
After a little more investigation of the XQuery Update standard, it looks to me like BaseX is doing this right and the standard does not allow for positioning of attribute insertions (unless there's another approach I've overlooked). In case anyone else has a similar question - all insert operations involving attributes resolve to the function upd:insertAttributes which does not allow for positioning. It appears as though the modifiers "as first" and "as last" are ignored in the case of attributes. I suppose this makes sense if the ordering of attributes in XML is unimportant and undefined. Can anyone clarify what the XML/XDM standard has to say on the topic of attribute ordering? It's a little confusing because many XML processors attempt to present attributes with some kind of explicit ordering (as an example, see the .NET XmlAttributeCollection class which allows programmatic insertion of attributes before/after a reference attribute). Thanks (again), Dave
Quoted text · Dave Glick · 8 lines
From: Dave Glick Sent: Friday, December 02, 2011 12:37 PM To: basex-talk at mailman.uni-konstanz.de Subject: Insert position of attributes How would one go about inserting an attribute at a specific position (i.e., somewhere other than at the front of the attribute list)? I would expect the following expression would do the trick: "insert node attribute aname {'avalue'} as last into //XYZ" but it still inserts the attribute at the front of the attribute list. By looking at the code in the InsertAttribute update primitive, I can see that it's hardcoded to insert at the front of the attribute list. Does this mean that there is no way to control attribute insertion location? Does the XQuery Update standard not allow such an update or is this a bug/oversight on the part of BaseX? Thanks! Dave
CG
Christian Grün3 Dec 2011 03:42 #
Hi Dave, as you already noted, the order of attributes is not explicitly specified in XQuery Update. In fact, it is even completely implementation dependent; see e.g. here: http://www.w3.org/TR/xpath-datamodel/#dm-attributes As a result, each XQuery implementation will follow its own logic to arrange attributes in query results. The same observation applies to namespaces that are specified as attributes (using the xmlns prefix). Hope this helps, Christian
Quoted text · Dave Glick · 66 lines
On Fri, Dec 2, 2011 at 6:46 PM, Dave Glick <dglick at dracorp.com> wrote: > After a little more investigation of the XQuery Update standard, it looks to > me like BaseX is doing this right and the standard does not allow for > positioning of attribute insertions (unless there’s another approach I’ve > overlooked). In case anyone else has a similar question – all insert > operations involving attributes resolve to the function upd:insertAttributes > which does not allow for positioning. It appears as though the modifiers “as > first” and “as last” are ignored in the case of attributes. > > > > I suppose this makes sense if the ordering of attributes in XML is > unimportant and undefined. Can anyone clarify what the XML/XDM standard has > to say on the topic of attribute ordering? It’s a little confusing because > many XML processors attempt to present attributes with some kind of explicit > ordering (as an example, see the .NET XmlAttributeCollection class which > allows programmatic insertion of attributes before/after a reference > attribute). > > > > Thanks (again), > > > > Dave > > > > From: Dave Glick > Sent: Friday, December 02, 2011 12:37 PM > To: basex-talk at mailman.uni-konstanz.de > Subject: Insert position of attributes > > > > How would one go about inserting an attribute at a specific position (i.e., > somewhere other than at the front of the attribute list)? I would expect the > following expression would do the trick: “insert node attribute aname > {'avalue'} as last into //XYZ” but it still inserts the attribute at the > front of the attribute list. > > > > By looking at the code in the InsertAttribute update primitive, I can see > that it’s hardcoded to insert at the front of the attribute list. Does this > mean that there is no way to control attribute insertion location? Does the > XQuery Update standard not allow such an update or is this a bug/oversight > on the part of BaseX? > > > > Thanks! > > > > Dave > > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
JC
Jan Vlčinský (CAD)4 Dec 2011 10:58 #
Hi Regarding the (not existent) requirement for attribute order: In http://www.w3.org/TR/2008/REC-xml-20081126/#sec-starttags there is a note "Note that the order of attribute specifications in a start-tag or empty-element tag is not significant." And my recommendation is: Do not put any extra requirements to any XML, which is not really needed. In case of attributes, you may and up promissing your consumers that the order of attributes will be as you define, and later you may have problems switching tools, which follow W3C recommendation, but not your extra promise. So the general advice is: keep your promises at minimum possible, it will easy work for you and also for your partners. The same often applies, when people start insisting on certain XML encoding, encoding or not encoding of special characters - all these requirements are more cosmetic then practical and often do originate from people, who do not understand the topic so well, but are well trained in the exercise "find three differences it those two pictures". Jan *Ing. Jan Vlčinský* CAD programy Slunečnicová 338/3, 734 01 Karviná Ráj, Czech Republic tel: +420-597 602 024; mob: +420-608 979 040 skype: janvlcinsky; GoogleTalk: jan.vlcinsky at gmail.com http://cz.linkedin.com/in/vlcinsky
Quoted text · Dave Glick · 67 lines
On 2 December 2011 18:46, Dave Glick <dglick at dracorp.com> wrote: > After a little more investigation of the XQuery Update standard, it looks > to me like BaseX is doing this right and the standard does not allow for > positioning of attribute insertions (unless there’s another approach I’ve > overlooked). In case anyone else has a similar question – all insert > operations involving attributes resolve to the function > upd:insertAttributes which does not allow for positioning. It appears as > though the modifiers “as first” and “as last” are ignored in the case of > attributes.**** > > ** ** > > I suppose this makes sense if the ordering of attributes in XML is > unimportant and undefined. Can anyone clarify what the XML/XDM standard has > to say on the topic of attribute ordering? It’s a little confusing because > many XML processors attempt to present attributes with some kind of > explicit ordering (as an example, see the .NET XmlAttributeCollection class > which allows programmatic insertion of attributes before/after a reference > attribute).**** > > ** ** > > Thanks (again),**** > > ** ** > > Dave**** > > ** ** > > *From:* Dave Glick > *Sent:* Friday, December 02, 2011 12:37 PM > *To:* basex-talk at mailman.uni-konstanz.de > *Subject:* Insert position of attributes**** > > ** ** > > How would one go about inserting an attribute at a specific position > (i.e., somewhere other than at the front of the attribute list)? I would > expect the following expression would do the trick: “insert node attribute > aname {'avalue'} as last into //XYZ” but it still inserts the attribute at > the front of the attribute list.**** > > ** ** > > By looking at the code in the InsertAttribute update primitive, I can see > that it’s hardcoded to insert at the front of the attribute list. Does this > mean that there is no way to control attribute insertion location? Does the > XQuery Update standard not allow such an update or is this a bug/oversight > on the part of BaseX?**** > > ** ** > > Thanks!**** > > ** ** > > Dave**** > > ** ** > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >

⚡Generated with XQuery