4000-520-616
欢迎来到免疫在线!(蚂蚁淘生物旗下平台)  请登录 |  免费注册 |  询价篮
主营:原厂直采,平行进口,授权代理(蚂蚁淘为您服务)
咨询热线电话
4000-520-616
当前位置: 首页 > 新闻动态 >
新闻详情
Xerces-C使用硬编码的xsd验证xml - IT屋-程序员软件开发技术分享...
来自 : www.it1352.com/18555...html 发布时间:2021-03-25

I\'m writing a library which takes xml files and parses them. To prevent users from feeding inalid xmls into my application i\'m using xerces to validate the xml files via an xsd.

However, i only manages to validate against xsd-files. Theoretically an user could just open this file and mess around with it. That\'s why i would like my xsd to be hardcoded in my library.

Unfortunately i haven\'t found a way to do this with XercesC++, yet.

That\'s how it is working right now...

bool XmlParser::validateXml(std::string a_XsdFilename) xercesc::XercesDOMParser domParser; if (domParser.loadGrammar(a_XsdFilename.c_str(), xercesc::Grammar::SchemaGrammarType) == NULL) throw Exceptions::Parser::XmlSchemaNotReadableException(); XercesParserErrorHandler parserErrorHandler; domParser.setErrorHandler( parserErrorHandler); domParser.setValidationScheme(xercesc::XercesDOMParser::Val_Always); domParser.setDoNamespaces(true); domParser.setDoSchema(true); domParser.setValidationSchemaFullChecking(true); domParser.parse(m_Filename.c_str()); return (domParser.getErrorCount() == 0);

std::string m_Filename is a member variable holding the path of the xml i validate.

std::string a_XsdFilename is the path to the xsd i validate against.

XercesParserErrorHandler inherits from xercesc::ErrorHandler and does error handling.

How can i replace std::string a_XsdFilename with something like std::string a_XsdText?Where std::string a_XsdText contains the schema definition itself instead of a path to a file containing the schema definition.

解决方案

I\'ll describe three ways of how to hardcode your XSD in your program:

本文链接: http://grammschems.immuno-online.com/view-749406.html

发布于 : 2021-03-25 阅读(0)
公司介绍
品牌分类
其他
联络我们
服务热线:4000-520-616
(限工作日9:00-18:00)
QQ :1570468124
手机:18915418616
官网:http://