diff --git a/scour.py b/scour.py index 5062f33..9b69595 100755 --- a/scour.py +++ b/scour.py @@ -2071,11 +2071,15 @@ def serializeXML(element, options, ind = 0, preserveWhitespace = False): outString += ' ' # preserve xmlns: if it is a namespace prefix declaration - if attr.namespaceURI == 'http://www.w3.org/2000/xmlns/' and attr.nodeName.find('xmlns') == -1: - outString += 'xmlns:' - outString += attr.nodeName + '=' + quot + attrValue + quot - - # TODO: when to set preserveWhitespace to true, with a value of 'none'? + if attr.prefix != None: + outString += attr.prefix + ':' + elif attr.namespaceURI != None: + if attr.namespaceURI == 'http://www.w3.org/2000/xmlns/' and attr.nodeName.find('xmlns') == -1: + outString += 'xmlns:' + elif attr.namespaceURI == 'http://www.w3.org/1999/xlink': + outString += 'xlink:' + outString += attr.localName + '=' + quot + attrValue + quot + if attr.nodeName == 'xml:space': if attrValue == 'preserve': preserveWhitespace = True diff --git a/testscour.py b/testscour.py index 4b5b390..7c8322f 100755 --- a/testscour.py +++ b/testscour.py @@ -944,6 +944,12 @@ class DoNotPrettyPrintWhenNestedWhitespacePreserved(unittest.TestCase): Use bold text ''', 'Whitespace not preserved when nested') + +class GetAttrPrefixRight(unittest.TestCase): + def runTest(self): + grad = scour.scourXmlFile('unittests/xml-namespace-attrs.svg').getElementsByTagNameNS(SVGNS, 'linearGradient')[1] + self.assertEquals( grad.getAttributeNS('http://www.w3.org/1999/xlink', 'href'), '#linearGradient841', + 'Did not get xlink:href prefix right' ) # TODO; write a test for embedding rasters # TODO: write a test for --disable-embed-rasters diff --git a/unittests/xml-namespace-attrs.svg b/unittests/xml-namespace-attrs.svg new file mode 100644 index 0000000..b1c5b11 --- /dev/null +++ b/unittests/xml-namespace-attrs.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file