繁体   English   中英

libxml2 xmlSchemaParse失败

[英]Libxml2 xmlSchemaParse failed

我有一个小项目(在c ++ linux ubuntu 14.04上),我尝试使用libxml2解析一些XML文档。 当我获取.xml文件时,我尝试对其进行验证。 但是有一些讨厌的错误!

我发现了有关在验证期间使用一些.xsd模式的信息。 为此,重要的是创建具有“ schemaLocation”元素的“ import”元素(针对每个.xsd模式)的.xsd文档。
有我的.xsd模式:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://osll.converter-schema"
    targetNamespace="http://osll.converter-schema"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:OAI-PMH="http://www.openarchives.org/OAI/2.0"
    xmlns:lido="http://www.lido-schema.org"
    version="1.0" elementFormDefault="qualified" attributeFormDefault="unqualified">

    <xs:import namespace="http://www.openarchives.org/OAI/2.0" schemaLocation="http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"/>   
    <xs:import namespace="http://www.lido-schema.org" schemaLocation="http://www.lido-schema.org/schema/v1.0/lido-v1.0.xsd"/>
</xs:schema>

有用于使用libxml2解析.xsd模式的c ++代码:

bool XmlDocument::validate(const char* fileSchema) {
    std::cout << "Starting validate xml-document..";
    xmlSchemaParserCtxtPtr schemaParser = xmlSchemaNewParserCtxt(fileSchema);
    xmlSchemaPtr schema = xmlSchemaParse(schemaParser);
    xmlSchemaValidCtxtPtr schemaValid = xmlSchemaNewValidCtxt(schema);
    int result = xmlSchemaValidateDoc(schemaValid, xmlDocument);
    if(result!=0) { std::cout << "Error! Code: " << result << std::endl; return false; }
    else { std::cout << "Done!\n"; return true; }
    return false;
}

最后是错误列表:

http://www.w3.org/1999/xlink.xsd:27 :元素导入:模式解析器警告:元素'{ http://www.w3.org/2001/XMLSchema } import':跳过导入的模式在“ http://www.w3.org/2001/xml.xsd ”的命名空间“ http://www.w3.org/XML/1998/namespace ”,因为这个名称空间已经与位于架构进口' http://www.w3.org/2001/03/xml.xsd '。
错误:操作进行中
I / O警告:无法加载外部实体“ http://schemas.opengis.net/gml/3.1.1/base/coverage.xsd
http://schemas.opengis.net/gml/3.1.1/base/gml.xsd:16 :元素包括:模式解析器错误:元素'{ http://www.w3.org/2001/XMLSchema } include' :无法加载包含的文档“ http://schemas.opengis.net/gml/3.1.1/base/coverage.xsd ”。 错误:操作进行中
I / O警告:无法加载外部实体“ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd
response.xml:3:元素OAI-PMH:模式有效性警告:元素'{ http://www.openarchives.org/OAI/2.0/ } OAI-PMH',属性'{ http://www.w3.org / 2001 / XMLSchema-instance } schemaLocation':位于位置' http://www.openarchives.org/OAI/2.0/OAI-PMH的文档。 无法获取“ xsd”。
response.xml:3:元素OAI-PMH:架构有效性错误:元素'{ http://www.openarchives.org/OAI/2.0/ } OAI-PMH':没有匹配的全局声明可用于验证根。

请帮忙寻找bug,我将非常高兴!

第一组错误消息抱怨解析器无法抓取其URL指定的外部XSD文件。

您正在运行的盒子是否可以访问Internet?

为了能够导入外部XSD文件,自然必须具有Internet访问权限。

在没有Internet访问的情况下,可以手动下载任何所需的外部文件,并通过xml目录文件将其本地加载。 但这是一个不同的,稍微复杂的话题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM