如何检查 XML 是否与 Xerces 格式正确
How to check if XML is well formed with Xerces
我正在使用Xerces C++ lib来解析XML。我需要一个函数来确定输入的 XML 格式是否正确。DOMConfiguration Interface
中提到了"格式良好",但没有解释如何使用它。
这就是我的代码到目前为止的样子。无论 XML 格式是否正确,它的工作方式都相同,但我需要知道它何时格式不正确。
try {
XMLPlatformUtils::Initialize();
// create the DOM parser
XercesDOMParser *parser = new XercesDOMParser;
parser->setValidationScheme(XercesDOMParser::Val_Never);
parser->parse(xml_input.c_str()); // where xml_input is my XML filename
// get the DOM representation
DOMDocument *doc = parser->getDocument();
// get the root element
DOMElement *root = doc->getDocumentElement();
}
catch ( DOMXPathException& e )
{
char* message = xercesc::XMLString::transcode( e.getMessage() );
cout << message << endl;
XMLString::release( &message );
}
您应该使用 WFXMLScanner 扫描程序仅执行格式良好的检查。关于如何将特定扫描仪与xerces一起使用,有一些很好的例子。
相关文章:
- 如何在openssl-ecc中获取十六进制格式的私钥
- 将"打开的CV图像"中的"颜色"转换为整数格式
- TDateTime格式在C++Builder中不会更改
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 检查不带转换的扫描格式
- 当我尝试使用 sstream 和分面将 Boost Time_duration转换为字符串时,我没有得到所需的格式
- 是否可以从格式字符串中检索"width"
- clang格式:宏的缩进
- clang格式:禁用排序包含
- 在用于格式4的arm模拟器中实现功能时的一个问题
- 将RGB图像保存为PPM格式
- 询问在设计我的手臂模拟器功能表示格式1
- 当使用比格式支持的精度更高的精度来显示数字时,会写出什么数据
- 带有Protobuf序列化的C++Hazelcast:字符串不是UTF-8格式的
- 如何将strftime中的格式错误作为异常捕获
- 将CHW格式的浮点向量转换为cv::Mat
- 如何将二进制格式的 C++ 对象的 std::vector 保存到磁盘?
- 如何以叮当格式设置评论的行长?
- 为什么我需要C++中不同的排序格式来对这个USACO代码上的数组和优先级队列进行排序
- 如何检查 XML 是否与 Xerces 格式正确