我有一个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>我希望使用QXmlStreamReader和QXmlStreamWriter复制文件,以便在整个复制过程中插入新元素。下面是我的代码,可以简单地复制该文件(一旦工作正常,我将在循环中插入代码,以便在此过程中添加其他元素):
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();
}这就产生了:
<?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>DictionarySet元素的xmlns属性是相反的,但我认为这并不重要。更大的问题是,我可以让QXmlStreamWriter在每个元素名之前不使用前缀"mc:“吗?
发布于 2015-05-18 20:56:08
QXmlStreamReader::setNamespaceProcessing()是答案:
reader.setNamespaceProcessing(false);https://stackoverflow.com/questions/30308458
复制相似问题