title: Programmatically editing xlsx XML causes it to become corrupt
body: <p>So I'm creating a Qt Program in Qt 5.6 that reads and writes to Excel files (Using Qt Xlsx 0.3). There is a drawing.xml file that I want to edit so I'm using a QDomDocument to do so. I change only one thing, from:</p>
  
  <pre><code>            &lt;a:p&gt;
                  &lt;a:pPr rtl="0"/&gt;
                  &lt;a:r&gt;
                      &lt;a:rPr b="0" baseline="0" i="0" lang="en-GB" sz="1100"&gt;
                          &lt;a:effectLst/&gt;
                          &lt;a:latin typeface="+mn-lt"/&gt;
                          &lt;a:ea typeface="+mn-ea"/&gt;
                          &lt;a:cs typeface="+mn-cs"/&gt;
                      &lt;/a:rPr&gt;
                      &lt;a:t&gt;J1: 0 &lt;/a:t&gt;
                  &lt;/a:r&gt;
              &lt;/a:p&gt;
  </code></pre>
  
  <p>to this:</p>
  
  <pre><code>            &lt;a:p&gt;
                  &lt;a:pPr rtl="0"/&gt;
                  &lt;a:r&gt;
                      &lt;a:rPr b="0" baseline="0" i="0" lang="en-GB" sz="1100"&gt;
                          &lt;a:effectLst/&gt;
                          &lt;a:latin typeface="+mn-lt"/&gt;
                          &lt;a:ea typeface="+mn-ea"/&gt;
                          &lt;a:cs typeface="+mn-cs"/&gt;
                      &lt;/a:rPr&gt;
                      &lt;a:t&gt;TESTING&lt;/a:t&gt;
                  &lt;/a:r&gt;
              &lt;/a:p&gt;
  </code></pre>
  
  <p>I put this back into the drawings folder and zipped up the xlsx file, but when I open the xlsx file the drawing was corrupt and it got removed. So I used a diffchecker to make sure that everything else is the same on these xml files, and noticed that Qt also made one change to it.</p>
  
  <p>From: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' standalone='yes'?&gt;
  </code></pre>
  
  <p>Fine, whatever, I edited the single quotes to be double quotes, and now the diff checker shows no differences. I place this drawing back inside the excel file and zip it up, but when I open the xlsx file the drawing still gets removed because it was corrupt! </p>
  
  <p>I thought there may be a problem with editing the xml file itself, so I tried editing the drawing.xml file by hand. I made the same change previously shown (just the "TESTING" and left the double quotes) and when I zip it back to an xlsx file there are no problems!</p>
  
  <p>I'm very confused whats causing this problem because the diff checker shows no differences between the xml files, yet when I try to zip them up into xlsx files, the one that is programmatically created by Qt is corrupt, while the hand edited one is fine. What could be the cause of this problem?</p>
  
  <p>EDIT: Here is the Qt code I am running:</p>
  
  <pre><code>QDomDocument doc;
  QString temp;
  int y, j;
  
  QFile xml("C:/Users/dillo/Desktop/drawing2.xml");
  
  if (!xml.open(QIODevice::ReadOnly)) {
      qDebug() &lt;&lt; "file didnt open";
  }
  
  if (!doc.setContent(&amp;xml, false, &amp;temp, &amp;y, &amp;j)) {
      qDebug() &lt;&lt; "Failed";
      qDebug() &lt;&lt; temp &lt;&lt; " " &lt;&lt; y &lt;&lt; " " &lt;&lt; j;
  }
  
  QDomNodeList items = doc.elementsByTagName("a:r");
  
  QDomNode node = items.at(1);
  QDomNodeList children = node.childNodes();
  
  QDomElement newNodeTag = doc.createElement(QString("a:t"));
  QDomText newNodeText = doc.createTextNode(QString("TESTING"));
  newNodeTag.appendChild(newNodeText);
  
  node.replaceChild(newNodeTag, children.at(1));
  
  xml.close();
  
  xml.open(QIODevice::WriteOnly);
  QTextStream stream(&amp;xml);
  stream &lt;&lt; doc.toString();
  
  xml.close();
  </code></pre>