     super()
     for own key, value of options
       @[key] = value
+    ## Force SVG namespace when parsing, so nodes have correct namespaceURI.
+    ## (This is especially important on the browser, so the results can be
+    ## reparented into an HTML Document.)
+    @svg = @svg.replace /^\s*<(?:[^<>'"\/]|'[^']*'|"[^"]*")*\s*(\/?\s*>)/,
+      (match, end) ->
+        unless 'xmlns' in match
+          match = match[...match.length-end.length] +
+            " xmlns='#{SVGNS}'" + match[match.length-end.length..]
+        match
     @xml = new DOMParser
       locator:  ## needed when specifying errorHandler
         line: 1

  XMLSerializer = xmldom.XMLSerializer
  prettyXML = require 'prettify-xml'
  graphemeSplitter = new require('grapheme-splitter')()

SVGNS = 'http://www.w3.org/2000/svg'
XLINKNS = 'http://www.w3.org/1999/xlink'


class Input
  @encoding: 'utf8'
  @parseFile: (filename, filedata) ->
    ## Generic method to parse file once we're already in the right class.
    input = new @
    input.filename = filename
    unless filedata?
      filedata = fs.readFileSync filename, encoding: @encoding
    input.parse filedata
    input
  @recognize: (filename, filedata) ->
    ## Recognize type of file and call corresponding class's `parseFile`.
    extension = extensionOf filename
    if extension of extensionMap
      extensionMap[extension].parseFile filename, filedata
    else
      throw new SVGTilerException "Unrecognized extension in filename #{filename}"

