Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Print attributes in order sorted by name

  • Loading branch information...
commit 46b23ce3c76e993a4b6ded9872795c0c35d7a03e 1 parent c851e41
@rubys authored
View
2  lib.py/treebuilders/simpletree.py
@@ -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)
View
2  lib.rb/treebuilders/simpletree.rb
@@ -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
8 tests/tree-construction1
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.