title: Batik - Modify and saving of SVG results in not well formed XML
body: <p>I'm trying to edit an existing SVG and save it afterwards using Batik (I need different formats and DOM-Manipulation).</p>
  
  <p>What I do:</p>
  
  <ul>
  <li>Adobe Illustrator Source File (CS 4.0) saved as SVG 1.0 with all Glyphs (two embedded Fonts) </li>
  <li>Loaded with Batik (using SAXSVGDocumentFactory, source below)</li>
  <li>DOM-Modifications (even without modifications the problem occurs)</li>
  <li>Saving using SVGTranscoder</li>
  </ul>
  
  <p>After transcoding I get a new SVG-File, which is filled with XML, but is not able to render properly in Firefox or Illustrator.</p>
  
  <p>In Firefox I get the message that the XML is not well formed e.g.,</p>
  
  <pre><code>&lt;glyph horiz-adv-x="249" unicode=""/&gt;
  </code></pre>
  
  <p>My Code:</p>
  
  <pre><code>///////////////
  // Load Template File (with embedded Fonts)
  ///////////////
  File file = new File(SVGFilePath);
  FileInputStream svgInputStream = new FileInputStream(file);
  
  ////////////////////
  // Load SVG into DOM-Tree
  ////////////////////
  String parser = XMLResourceDescriptor.getXMLParserClassName();
  SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
  Document doc = factory.createDocument(parser, svgInputStream);
  
  //...
  
  ///////////////////////
  // Generate Output File
  ///////////////////////
  String savepath = "test.svg";
  byte[] fileData = transcodeToSVG(doc);
  FileOutputStream fileSave = new FileOutputStream(savepath);
  fileSave.write(fileData);
  fileSave.close();
  </code></pre>
  
  <p>My Transcoding Code:</p>
  
  <pre><code>public byte[] transcodeToSVG(Document doc) throws TranscoderException {
  
      try {
          //Determine output type:
          SVGTranscoder t = new SVGTranscoder();
  
          //Set transcoder input/output
          TranscoderInput input = new TranscoderInput(doc);
          ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
          OutputStreamWriter ostream = new OutputStreamWriter(bytestream);
          TranscoderOutput output = new TranscoderOutput(ostream);
  
          //Perform transcoding
          t.transcode(input, output);
          ostream.flush();
          ostream.close();
  
          return bytestream.toByteArray();
  
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      return null;
  }
  </code></pre>