QXmlStreamWriter модификация файла xml
Пытаюсь модифицировать xml код. Мне нужно добавить в узел код с сохранением предыдущего.
XML файл в который мне нужно добавить код имеет вид:
<office:automatic-styles>
<style:style style:name="c10" style:family="text">
<style:text-properties fo:font-family="TimesNewRoman" fo:font-size="12pt" fo:text-transform="none" fo:letter-spacing="0pt" style:text-underline-type="none" style:text-line-through-type="none" style:text-underline-style="none"/>
</style:style>
<style:style style:name="TB28.33" style:family="table-cell">
<style:table-cell-properties fo:border="0.75pt solid #000000" fo:padding-top="0.75pt" fo:padding-bottom="0.75pt" fo:padding-left="0.48pt" />
</style:style>
</office:automatic-styles>
Мне нужно добавить код между <office:automatic-styles> </office:automatic-styles>
Для этого сделал:
QString xmlCode(
"\n"
"<style:page-layout-properties fo:page-width=\"21.59cm\" fo:page-height=\"27.94cm\" style:num-format=\"1\" style:print-orientation=\"portrait\" fo:margin-top=\"2cm\" fo:margin-bottom=\"2cm\" fo:margin-left=\"2cm\" fo:margin-right=\"2cm\" style:writing-mode=\"lr-tb\" style:layout-grid-color=\"#c0c0c0\" style:layout-grid-lines=\"44\" style:layout-grid-base-height=\"0.55cm\" style:layout-grid-ruby-height=\"0cm\" style:layout-grid-mode=\"none\" style:layout-grid-ruby-below=\"false\" style:layout-grid-print=\"true\" style:layout-grid-display=\"true\" style:footnote-max-height=\"0cm\">"
"\n"
"<style:footnote-sep style:width=\"0.018cm\" style:distance-before-sep=\"0.101cm\" style:distance-after-sep=\"0.101cm\" style:line-style=\"none\" style:adjustment=\"left\" style:rel-width=\"25%\" style:color=\"#000000\"/>"
"\n"
"</style:page-layout-properties>"
"\n"
"<style:header-style>"
"\n"
"<style:header-footer-properties fo:min-height=\"0cm\" fo:margin-left=\"0cm\" fo:margin-right=\"0cm\" fo:margin-bottom=\"0.499cm\"/>"
"\n"
"</style:header-style>"
"\n"
"<style:footer-style>"
"\n"
"<style:header-footer-properties fo:min-height=\"0cm\" fo:margin-left=\"0cm\" fo:margin-right=\"0cm\" fo:margin-top=\"0.499cm\"/>"
"\n"
"</style:footer-style>"
"\n"
);
QFile file("/media/usb0/folder/content.xml");
if (!file.open(QIODevice::ReadWrite))
return;
QXmlStreamWriter xmlWriter(&file);
xmlWriter.setAutoFormatting(true);
xmlWriter.writeStartDocument();
xmlWriter.writeStartElement("office:automatic-styles");
xmlWriter.writeCharacters(xmlCode);
xmlWriter.writeEndElement();
Но получил:
<office:automatic-styles>
<style:page-layout-properties fo:page-width="21.59cm" fo:page-height="27.94cm" style:num-format="1" style:print-orientation="portrait" fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm" style:writing-mode="lr-tb" style:layout-grid-color="#c0c0c0" style:layout-grid-lines="44" style:layout-grid-base-height="0.55cm" style:layout-grid-ruby-height="0cm" style:layout-grid-mode="none" style:layout-grid-ruby-below="false" style:layout-grid-print="true" style:layout-grid-display="true" style:footnote-max-height="0cm">
<style:footnote-sep style:width="0.018cm" style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" style:line-style="none" style:adjustment="left" style:rel-width="25%" style:color="#000000"/>
</style:page-layout-properties>
<style:header-style>
<style:header-footer-properties fo:min-height="0cm" fo:margin-left="0cm" fo:margin-right="0cm" fo:margin-bottom="0.499cm"/>
</style:header-style>
<style:footer-style>
<style:header-footer-properties fo:min-height="0cm" fo:margin-left="0cm" fo:margin-right="0cm" fo:margin-top="0.499cm"/>
</style:footer-style>
</office:automatic-styles>ell-properties fo:padding-top="0.75pt" fo:padding-bottom="0.75pt" fo:padding-left="0.48pt"/>
</style:style>
<style:style style:name="Table5" style:family="table">
<style:table-properties table:border-model="collapsing"/>
</style:style>