【问题标题】:Validating an XML document fails to load schemas referenced with relative paths from within original XSD document验证 XML 文档无法加载使用原始 XSD 文档中的相对路径引用的架构
【发布时间】:2021-08-31 07:17:37
【问题描述】:

如果我从 xmlSchemaNewParserCtxt() 开始,解析器很好,可以找到所有引用的模式,但我想知道如果我使用 xmlSchemaNewMemParserCtxt(),我是否能以某种方式告诉它模式在哪里。

问题是,如果我已经在内存中下载了 XSD,我可以将文档 URL 传递给解析器以便它找到相关的东西吗?

一)

char *urlPath = "http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd";
xmlSchemaNewParserCtxt (urlPath);

b)

xmlSchemaNewMemParserCtxt (schemaBuffer, buffSize);

变体 a) 工作正常,变体 b) 产生错误 I/O 警告:未能加载外部实体“../common/UBL-CommonAggregateComponents-2.1.xsd”

架构位于此处:http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd

【问题讨论】:

    标签: c validation xsd libxml2


    【解决方案1】:

    最好的解决方案可能是使用 XML 目录,但您也可以使用 xmlRegisterInputCallbacksxmlSetExternalEntityLoader 控制子资源的加载。

    【讨论】:

    • 谢谢,我同时放弃了第二个变体,这就是为什么我稍后会接受你的回答:)
    猜你喜欢
    • 2014-01-22
    • 2010-11-18
    • 2013-05-21
    • 1970-01-01
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 2012-06-04
    • 2018-12-05
    相关资源
    最近更新 更多