From 76c7b1e027797254e2d03fea748efe9ca4caa161 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Thu, 30 Sep 2010 19:45:36 +0100 Subject: Replace parseString() calls with createElement() This seems cleaner... I'm not sure if it actually is, but hey. --- tools/specparser.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/tools/specparser.py b/tools/specparser.py index bd0ac822..d555e0b9 100644 --- a/tools/specparser.py +++ b/tools/specparser.py @@ -179,9 +179,15 @@ class Base(object): try: node.removeAttribute('version') - span = xml.dom.minidom.parseString( - ('%s\n' % txt) % - nnode.getAttribute('version')).firstChild + doc = self.get_spec().document + + span = doc.createElement('span') + span.setAttribute('class', 'version') + + text = doc.createTextNode( + txt % nnode.getAttribute('version') + ' ') + span.appendChild(text) + node.insertBefore(span, node.firstChild) except xml.dom.NotFoundErr: raise MissingVersion( @@ -223,6 +229,7 @@ class Base(object): def _convert_to_html(self, node): spec = self.get_spec() + doc = spec.document root_namespace = self.get_root_namespace() # rewrite @@ -231,22 +238,27 @@ class Base(object): if nested: raise Xzibit(n, nested[0]) - rationale_div = xml.dom.minidom.parseString( - """ + """
Rationale:
-
+
<- inner_div
- """).documentElement - n.parentNode.replaceChild(rationale_div, n) + """ + outer_div = doc.createElement('div') + outer_div.setAttribute('class', 'rationale') - # It's the third child: space, h5, space, div - inner_div = rationale_div.childNodes[3] - assert inner_div.nodeName == 'div', inner_div + h5 = doc.createElement('h5') + h5.appendChild(doc.createTextNode('Rationale:')) + outer_div.appendChild(h5) + + inner_div = doc.createElement('div') + outer_div.appendChild(inner_div) for rationale_body in n.childNodes: inner_div.appendChild(rationale_body.cloneNode(True)) + n.parentNode.replaceChild(outer_div, n) + # rewrite for n in node.getElementsByTagNameNS(XMLNS_TP, 'type'): t = spec.lookup_type(getText(n)) -- cgit v1.2.3