首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Libxml2 xmlSchemaParse失败

Libxml2 xmlSchemaParse失败
EN

Stack Overflow用户
提问于 2014-09-02 19:09:28
回答 1查看 1.8K关注 0票数 1

我有一个小项目(在c++ Linuxubuntu14.04上),我试图使用libxml2解析一些。当我得到.xml文件时,我试图验证它。但也有一些严重的错误!

我发现了有关在验证期间使用几个.xsd模式的信息。为此,创建具有“导入”元素(对于每个.xsd模式)具有'schemaLocation‘元素的schemaLocation文档非常重要。

这是我的.xsd模式:

代码语言:javascript
复制
<?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>

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

代码语言:javascript
复制
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}导入”:跳过命名空间“http://www.w3.org/XML/1998/namespace”位于“http://www.w3.org/2001/xml.xsd”处的模式导入,因为此命名空间已经导入,模式位于“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: element OAI-PMH: Schemas有效性警告:元素'{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: element OAI-PMH: Schemas有效性错误:元素'{http://www.openarchives.org/OAI/2.0/}OAI-PMH':验证根没有匹配的全局声明。

请帮忙找虫,我会很高兴的!

EN

回答 1

Stack Overflow用户

发布于 2014-09-02 22:25:29

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

你运行的这个盒子能上网吗?

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

就Internet访问而言,可以手动下载任何需要的外部文件,并通过xml目录文件在本地加载它们;但这是一个不同的、稍微复杂一些的主题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25630597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档