Permalink
Browse files

Print attributes in order sorted by name

  • Loading branch information...
1 parent c851e41 commit 46b23ce3c76e993a4b6ded9872795c0c35d7a03e @rubys committed Jan 16, 2011
Showing with 6 additions and 6 deletions.
  1. +1 −1 lib.py/treebuilders/simpletree.py
  2. +1 −1 lib.rb/treebuilders/simpletree.rb
  3. +4 −4 tests/tree-construction1
@@ -94,7 +94,7 @@ def printTree(self, indent):
tree = '\n|%s<%s> (%s, %s, %s)' % (' '*indent, self.name, self.prefix, self.localname, self.namespace)
indent += 2
if self.attributes:
- for token in self.attributes:
+ for token in sorted(self.attributes, key=lambda token: token["name"]):
tree += '\n|%s%s="%s" (%s, %s, %s)' % (' ' * indent, token["name"], token["value"], token["prefix"], token["localname"], token["namespace"])
for child in self.childNodes:
tree += child.printTree(indent)
@@ -127,7 +127,7 @@ def printTree(indent)
"(#{@prefix}, #{@localname}, #{@namespace})"
indent += 2
if @attributes
- for token in @attributes
+ for token in @attributes.sort_by {|token| token["name"]}
tree += "\n|#{' ' * indent}#{token["name"]}=\"#{token["value"]}\" " +
"(#{token["prefix"]}, #{token["localname"]}, #{token["namespace"]})"
end
View
@@ -16,8 +16,8 @@
#errors
#document
| <x:z> (x, z, y)
-| xmlns:x="y" (xmlns, x, http://www.w3.org/2000/xmlns/)
| xml:foo:bar="f" (xml, foo:bar, http://www.w3.org/XML/1998/namespace)
+| xmlns:x="y" (xmlns, x, http://www.w3.org/2000/xmlns/)
#data
<xml:foobar/>
@@ -93,8 +93,8 @@ Bogus comment
#errors
#document
| <x> (, x, )
-| y="x" (, y, )
| x="TEST" (, x, )
+| y="x" (, y, )
#data
<!DOCTYPE x [
@@ -115,8 +115,8 @@ Bogus comment
#errors
#document
| <x> (, x, )
-| y="x" (, y, )
| x="TEST" (, x, )
+| y="x" (, y, )
#data
<!DOCTYPE x [
@@ -238,6 +238,6 @@ Bogus comment
#errors
#document
| <x> (, x, )
+| x:id="" (x, id, a)
| xmlns:x="a" (xmlns, x, http://www.w3.org/2000/xmlns/)
| xmlns:y="a" (xmlns, y, http://www.w3.org/2000/xmlns/)
-| x:id="" (x, id, a)

0 comments on commit 46b23ce

Please sign in to comment.