这里解析XML是我的代码:' 0' 出现时使用Xerces
XercesDOMParser domParser;
MemBufInputSource* basic_mem = new MemBufInputSource(
(const XMLByte*)(xmlString.c_str()),//xmlString is a std::string that contains xml
xmlString.length(),//this std::string's length
"dummy");
ParserErrorHandler parserErrorHandler;
domParser.setErrorHandler(&parserErrorHandler);
domParser.setExitOnFirstFatalError(true);
domParser.setValidationConstraintFatal(true);
domParser.setValidationScheme(XercesDOMParser::Val_Auto);
domParser.setDoNamespaces(true);
domParser.setDoSchema(true);
domParser.parse(*basic_mem);
我的XML字符串,是这样的:
xmlString = "\
<root>\r\n\
<somenode someattr="[email protected]"/>\r\n\
</root>"
然后我用xmlString.replace( '@', '\ 0')添加'\ 0'。
这里是问题:如果xmlString内部包含'\ 0',解析器将报告错误: “意外的输入结束”。我认为这是因为'\ 0'。但我确信xmlString是完整的,并且xmlString.length()是正确的。 ,所以我想这个 '\ 0' 进入CDATA:
xmlString = "\
<root>\r\n\
<somenode>\r\n\
<![CDATA[abc\0def]]>\r\n\
</somenode>\r\n\
</root>"
然后解析器报告 “CDATA意外结束” ... 我能做些什么来解决这个问题?任何建议都会完成!
XML中不允许使用'NUL'字符。请参见[XML规范](http://www.w3.org/TR/xml11/#charsets)。 – ach