Anonymous avatar Anonymous committed d19e8a2

Attribute order in parsed XML is now preserved.

Comments (0)

Files changed (4)

  * The XHTML serializer now correctly handles elements in foreign namespaces
    (such as SVG or MathML).
  * Fixed relative includes in templates on Windows (ticket #27).
- * Output can be encoded using legacy codecs such as ISO-8859-1, any character
+ * Output can be encoded using legacy codecs such as ISO-8859-1. Any character
    not representable in the chosen encoding gets replaced by the corresponding
    XML character reference.
  * String literals in XPath expressions that contain spaces are now parsed
         parser = expat.ParserCreate('utf-8', '}')
         parser.buffer_text = True
         parser.returns_unicode = True
+        parser.ordered_attributes = True
+
         parser.StartElementHandler = self._handle_start
         parser.EndElementHandler = self._handle_end
         parser.CharacterDataHandler = self._handle_data
                 self.expat.CurrentColumnNumber)
 
     def _handle_start(self, tag, attrib):
-        self._enqueue(START, (QName(tag), Attributes(attrib.items())))
+        self._enqueue(START, (QName(tag), Attributes(zip(*[iter(attrib)] * 2))))
 
     def _handle_end(self, tag):
         self._enqueue(END, QName(tag))

markup/tests/input.py

         if sys.version_info[:2] >= (2, 4):
             self.assertEqual((None, 1, -1), pos)
 
+    def test_element_attribute_order(self):
+        text = '<elem title="baz" id="foo" class="bar" />'
+        events = list(XMLParser(StringIO(text)))
+        kind, data, pos = events[0]
+        self.assertEqual(Stream.START, kind)
+        tag, attrib = data
+        self.assertEqual(u'elem', tag)
+        self.assertEqual((u'title', u'baz'), attrib[0])
+        self.assertEqual((u'id', u'foo'), attrib[1])
+        self.assertEqual((u'class', u'bar'), attrib[2])
+
 
 class HTMLParserTestCase(unittest.TestCase):
 

markup/tests/output.py

           <body>
             <button>
               <svg:svg width="600px" height="400px">
-                <svg:polygon points="50,50 50,300 300,300" />
+                <svg:polygon id="triangle" points="50,50 50,300 300,300" />
               </svg:svg>
             </button>
           </body>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.