-
Notifications
You must be signed in to change notification settings - Fork 294
Preserve order of attributes on serialization #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
On the whole I think we should get rid of the Note, also, that no tree type we support preserves order: lxml explicitly returns them in an "arbitrary order", as such there is no guarantee the treewalker won't change iteration order (and it probably does, for it just returns a dict). |
This doesn't do anything about the fact that none of our treebuilders preserve attribute order: it merely avoids the serializer reordering them from the order it receives them in. This changes the serializer tests to use an OrderedDict to get alphabetical order so they continue to meet their expectations.
This doesn't do anything about the fact that none of our treebuilders preserve attribute order: it merely avoids the serializer reordering them from the order it receives them in. This changes the serializer tests to use an OrderedDict to get alphabetical order so they continue to meet their expectations.
Another aspect to this issue is that attribute order is shuffled on parse, not just on serialization. The tokenizer preserves attribute ordering, but that is undone in the def normalizeToken(self, token):
""" HTML5 specific normalizations to the token stream """
if token["type"] == tokenTypes["StartTag"]:
token["data"] = dict(token["data"][::-1])
return token To achieve good ordering throughout the parse/reserialize roundtrip, this dict would also need to be changed to OrderedDict. |
Is that the only change needed? I was suspecting it was going to be more than that! |
I think it is necessary but not sufficient. When I changed it to |
From Google Code #153:
The text was updated successfully, but these errors were encountered: