- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
XML attribute position
Tue, 2010-01-12, 16:30
He,
I am computing XPath expressions but for attributes it seems like their position is somehow changed:
$ scala
Welcome to Scala version 2.7.7.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_17).
Type in expressions to have them evaluated.
Type :help for more information.
scala>
res0: scala.xml.Elem =
scala>
So, referring to "/attribute::*[2.0]" gives me the "c" attribute rather than the "b" attribute :(
Any suggestions?
Cheers,
--
Normen Müller
Tue, 2010-01-12, 16:47
#2
Re: XML attribute position
This is actually legal XML. The XML Spec says that attributes are not ordered.
You should access the attributes by name or value not by position.
Regards
Stefan
2010/1/12 Normen Müller <normen.mueller@googlemail.com>
You should access the attributes by name or value not by position.
Regards
Stefan
2010/1/12 Normen Müller <normen.mueller@googlemail.com>
He,
I am computing XPath expressions but for attributes it seems like their position is somehow changed:
$ scala
Welcome to Scala version 2.7.7.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_17).
Type in expressions to have them evaluated.
Type :help for more information.
scala> <test a="A" b="B" c="C"/>
res0: scala.xml.Elem = <test a="A" c="C" b="B"></test>
scala>
So, referring to "/attribute::*[2.0]" gives me the "c" attribute rather than the "b" attribute :(
Any suggestions?
Cheers,
--
Normen Müller
Tue, 2010-01-12, 16:47
#3
Re: XML attribute position
On Tue, Jan 12, 2010 at 04:29:58PM +0100, Normen Müller wrote:
> scala>
> res0: scala.xml.Elem =
https://lampsvn.epfl.ch/trac/scala/ticket/2735
I have no idea why it doesn't preserve ordering. AFAIK according to
spec it's not supposed to matter, but we all know in real life it does.
Tue, 2010-01-12, 16:57
#4
Re: Re: XML attribute position
Thanks Stefan & Paul for your fast reply!
@Stefan: Yes, you are /absolutely/ right, but as Paul already said ``but we all know in real life it does'' and so it does to me :(
So, I guess I have to wait for a fix, or try to go Stefan's, say proper, way ;)
On Jan 12, 2010, at 4:35 PM, Paul Phillips wrote:
> On Tue, Jan 12, 2010 at 04:29:58PM +0100, Normen Müller wrote:
>> scala>
>> res0: scala.xml.Elem =
>
> https://lampsvn.epfl.ch/trac/scala/ticket/2735
>
> I have no idea why it doesn't preserve ordering. AFAIK according to
> spec it's not supposed to matter, but we all know in real life it does.
>
Tue, 2010-01-12, 16:57
#5
Re: Re: XML attribute position
Thanks Stefan & Paul for your fast reply!
@Stefan: Yes, you are /absolutely/ right, but as Paul already said ``but we all know in real life it does'' and so it does to me :(
So, I guess I have to wait for a fix, or try to go Stefan's, say proper, way ;)
On Jan 12, 2010, at 4:35 PM, Paul Phillips wrote:
> On Tue, Jan 12, 2010 at 04:29:58PM +0100, Normen Müller wrote:
>> scala>
>> res0: scala.xml.Elem =
>
> https://lampsvn.epfl.ch/trac/scala/ticket/2735
>
> I have no idea why it doesn't preserve ordering. AFAIK according to
> spec it's not supposed to matter, but we all know in real life it does.
>
Tue, 2010-01-12, 17:07
#6
Re: Re: XML attribute position
2010/1/12 Normen Müller <normen.mueller@googlemail.com>
Regards
Stefan
Thanks Stefan & Paul for your fast reply!I understand that just wanted to say that it might not be likely that there will be a fix as it is not a bug per spec.
@Stefan: Yes, you are /absolutely/ right, but as Paul already said ``but we all know in real life it does'' and so it does to me :(
Regards
Stefan
So, I guess I have to wait for a fix, or try to go Stefan's, say proper, way ;)
On Jan 12, 2010, at 4:35 PM, Paul Phillips wrote:
> On Tue, Jan 12, 2010 at 04:29:58PM +0100, Normen Müller wrote:
>> scala> <test a="A" b="B" c="C"/>
>> res0: scala.xml.Elem = <test a="A" c="C" b="B"></test>
>
> https://lampsvn.epfl.ch/trac/scala/ticket/2735
>
> I have no idea why it doesn't preserve ordering. AFAIK according to
> spec it's not supposed to matter, but we all know in real life it does.
>
> --
> Paul Phillips | Every election is a sort of advance auction sale
> Caged Spirit | of stolen goods.
> Empiricist | -- H. L. Mencken
> pp: i haul pills |----------* http://www.improving.org/paulp/ *----------
Cheers,
--
Normen Müller
Tue, 2010-01-12, 17:17
#7
Re: XML attribute position
Let's put that in perspective. It is a *huge mistake*, as well as a
violation of the XML specification, to process XML in a way that assigns
any information content to the order of the attributes. You should simply
process attributes by name, not position.
There is a different issue with XML serialisation, where you might have a
valid reason for wanting to control the order of attributes, e.g. to make
it easier to do diffs between versions. However, this has nothing to do
with processing or interpretation of the information in the XML.
That XPath is simply a bad XPath to use. It isn't illegal, but it's a
mistake to expect the attributes to be in document order, since the XML
specification is very explicit about attributes not being interpreted that
way.
Cheers, Tony.
On Tue, 12 Jan 2010 15:35:20 -0000, Paul Phillips
wrote:
> On Tue, Jan 12, 2010 at 04:29:58PM +0100, Normen Müller wrote:
>> scala>
>> res0: scala.xml.Elem =
>
> https://lampsvn.epfl.ch/trac/scala/ticket/2735
>
> I have no idea why it doesn't preserve ordering. AFAIK according to
> spec it's not supposed to matter, but we all know in real life it does.
Tue, 2010-01-12, 17:17
#8
Re: XML attribute position
Let's put that in perspective. It is a *huge mistake*, as well as a
violation of the XML specification, to process XML in a way that assigns
any information content to the order of the attributes. You should simply
process attributes by name, not position.
There is a different issue with XML serialisation, where you might have a
valid reason for wanting to control the order of attributes, e.g. to make
it easier to do diffs between versions. However, this has nothing to do
with processing or interpretation of the information in the XML.
That XPath is simply a bad XPath to use. It isn't illegal, but it's a
mistake to expect the attributes to be in document order, since the XML
specification is very explicit about attributes not being interpreted that
way.
Cheers, Tony.
On Tue, 12 Jan 2010 15:35:20 -0000, Paul Phillips
wrote:
> On Tue, Jan 12, 2010 at 04:29:58PM +0100, Normen Müller wrote:
>> scala>
>> res0: scala.xml.Elem =
>
> https://lampsvn.epfl.ch/trac/scala/ticket/2735
>
> I have no idea why it doesn't preserve ordering. AFAIK according to
> spec it's not supposed to matter, but we all know in real life it does.
Tue, 2010-01-12, 17:27
#9
Re: XML attribute position
On Jan 12, 2010, at 5:12 PM, Anthony B. Coates (Londata) wrote:
> Let's put that in perspective. It is a *huge mistake*, as well as a violation of the XML specification, to process XML in a way that assigns any information content to the order of the attributes. You should simply process attributes by name, not position.
Yes, I got that, but...
> There is a different issue with XML serialisation, where you might have a valid reason for wanting to control the order of attributes, e.g. to make it easier to do diffs between versions. However, this has nothing to do with processing or interpretation of the information in the XML.
...actually I need the order to compute XUpdates. And, as to me, I expect if I read an XML file with Scala API, do nothing with it and then write it back to a new file, besides others, the order of attributes should be the same (although the XML Spec tells me the order of attributes doesn't matter). I again refer to Paul, that in real life it sometimes matters.
To make it clear: Stefan and you, Anthony, are absolutely right regarding the XML Spec but I would appreciate a fix for #2735 anyway.
> That XPath is simply a bad XPath to use. It isn't illegal, but it's a mistake to expect the attributes to be in document order, since the XML specification is very explicit about attributes not being interpreted that way.
Cheers,
--
Normen Müller
Tue, 2010-01-12, 17:27
#10
Re: XML attribute position
On Jan 12, 2010, at 5:12 PM, Anthony B. Coates (Londata) wrote:
> Let's put that in perspective. It is a *huge mistake*, as well as a violation of the XML specification, to process XML in a way that assigns any information content to the order of the attributes. You should simply process attributes by name, not position.
Yes, I got that, but...
> There is a different issue with XML serialisation, where you might have a valid reason for wanting to control the order of attributes, e.g. to make it easier to do diffs between versions. However, this has nothing to do with processing or interpretation of the information in the XML.
...actually I need the order to compute XUpdates. And, as to me, I expect if I read an XML file with Scala API, do nothing with it and then write it back to a new file, besides others, the order of attributes should be the same (although the XML Spec tells me the order of attributes doesn't matter). I again refer to Paul, that in real life it sometimes matters.
To make it clear: Stefan and you, Anthony, are absolutely right regarding the XML Spec but I would appreciate a fix for #2735 anyway.
> That XPath is simply a bad XPath to use. It isn't illegal, but it's a mistake to expect the attributes to be in document order, since the XML specification is very explicit about attributes not being interpreted that way.
Cheers,
--
Normen Müller
Tue, 2010-01-12, 18:07
#11
Re: XML attribute position
Le mardi 12 janvier 2010 à 17:22 +0100, Normen Müller a écrit :
> ...actually I need the order to compute XUpdates. And, as to me, I
> expect if I read an XML file with Scala API, do nothing with it and
> then write it back to a new file, besides others, the order of
> attributes should be the same (although the XML Spec tells me the
> order of attributes doesn't matter).
Some XML standards also say that this should not be relied upon -
notably the W3C Infoset spec that is about as close to a "standard" XML
representation as you can get.
In other words, this is not a quirk that is likely to be unique to
Scala.
The reason specs such as the W3C infoset one allow some details of
documents to be ignored is that this makes implementing the standard
simpler and more efficient. If attribute order matters, you can't just
hash the attributes, for example, you have to preserve the order
information somewhere. If you have a mutable data structure and you add
an attribute, you have to decide which position the new attribute will
hold (unless order only matters until you add an attribute, which would
be a bit odd). And so on.
Wed, 2010-01-13, 18:27
#12
Re: XML attribute position
On Tue, Jan 12 2010 17:03:44 +0000, mark@cyberporte.com wrote:
...
> The reason specs such as the W3C infoset one allow some details of
> documents to be ignored is that this makes implementing the standard
> simpler and more efficient. If attribute order matters, you can't just
If you looked into it, you'd find that attribute order isn't significant
in SGML, so (a) preserving attribute order possibly wasn't in the
mindset of the designers of XML and (b) making attribute order
significant in XML would have made it harder to bootstrap XML because it
would stop (some, possibly all) SGML parsers from being used to parse
XML.
It's not a new problem, but it's also not something that many people
find to be important. A looong time ago, we used a SGML parser to
validate hand-edited SGML. The parser could output the reconstructed
valid SGML (sans insignificant whitespace, etc.), but it always
faithfully reversed the order of the attributes. We would check the
valid result back into the version control system, so, to minimise
unnecessary diffs, we parsed the valid output again to get the
attributes back in the original order before checking it in. If the
parser had been less predictable about attribute order, I expect we
would have either lived with it or used Perl to fix it the output.
Regards,
Tony Graham Tony.Graham@MenteithConsulting.com
Director W3C XSL FO SG Invited Expert
Menteith Consulting Ltd XML Guild member
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599 http://www.menteithconsulting.com
On Tue, Jan 12, 2010 at 04:29:58PM +0100, Normen Müller wrote:
> scala>
> res0: scala.xml.Elem =
https://lampsvn.epfl.ch/trac/scala/ticket/2735
I have no idea why it doesn't preserve ordering. AFAIK according to
spec it's not supposed to matter, but we all know in real life it does.