Reputation: 3197
I have this dictionary.xml:
<?xml version="1.0" encoding="UTF-8"?>
<DictionarySet xmlns:mc="urn:fmosoft-map-creator" xmlns="urn:fmosoft-map-creator" Version="1">
<Dictionary SourceLanguage="en_US" SourceLanguageIsPredefined="true" TargetLanguage="es" TargetLanguageIsPredefined="true">
<Translation Source="asdf" Target="fdsa"/>
<Translation Source="xyz" Target="jkl"/>
</Dictionary>
<Dictionary SourceLanguage="en_US" SourceLanguageIsPredefined="true" TargetLanguage="pt" TargetLanguageIsPredefined="true">
<Translation Source="asdf" Target="wer"/>
<Translation Source="xyz" Target="poi"/>
</Dictionary>
</DictionarySet>
I want to copy the file using QXmlStreamReader and QXmlStreamWriter, so I can insert new elements throughout the copy. Here is my code to simply copy the file (once this is working, I'll insert code in the loop to add additional elements along the way):
QXmlStreamWriter writer(&output);
if (!output.open(QIODevice::WriteOnly | QIODevice::Text)) {
throw std::runtime_error("Unable to open the file for writing.");
}
writer.setAutoFormatting(true);
writer.writeDefaultNamespace("urn:fmosoft-map-creator");
while (!reader.atEnd()) {
writer.writeCurrentToken(reader);
reader.readNext();
}
This produces:
<?xml version="1.0" encoding="UTF-8"?>
<mc:DictionarySet xmlns="urn:fmosoft-map-creator" xmlns:mc="urn:fmosoft-map-creator" Version="1">
<mc:Dictionary SourceLanguage="en_US" SourceLanguageIsPredefined="true" TargetLanguage="es" TargetLanguageIsPredefined="true">
<mc:Translation Source="asdf" Target="fdsa"/>
<mc:Translation Source="xyz" Target="jkl"/>
</mc:Dictionary>
<mc:Dictionary SourceLanguage="en_US" SourceLanguageIsPredefined="true" TargetLanguage="pt" TargetLanguageIsPredefined="true">
<mc:Translation Source="asdf" Target="wer"/>
<mc:Translation Source="xyz" Target="poi"/>
</mc:Dictionary>
</mc:DictionarySet>
The xmlns attributes of the DictionarySet element are reversed, but I don't think that matters. The bigger issue is, can I get QXmlStreamWriter to NOT use the prefix "mc:" before each element name?
Upvotes: 0
Views: 545
Reputation: 3197
QXmlStreamReader::setNamespaceProcessing() is the answer:
reader.setNamespaceProcessing(false);
Upvotes: 1