简体   繁体   English

libxml2 xmlSchemaParse失败

[英]Libxml2 xmlSchemaParse failed

I have a little project (on c++ linux ubuntu 14.04) where I trying to parse some XML document using libxml2. 我有一个小项目(在c ++ linux ubuntu 14.04上),我尝试使用libxml2解析一些XML文档。 When I get .xml file I trying to validate it. 当我获取.xml文件时,我尝试对其进行验证。 But there are some nasty errors! 但是有一些讨厌的错误!

I found information about using a few .xsd schemas during validation. 我发现了有关在验证期间使用一些.xsd模式的信息。 For this it is important to create .xsd document with "import" elements (for each of .xsd schema) that have 'schemaLocation' element. 为此,重要的是创建具有“ schemaLocation”元素的“ import”元素(针对每个.xsd模式)的.xsd文档。
There is my .xsd schema: 有我的.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>

There is c++ code for parsing .xsd schema using libxml2: 有用于使用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;
}

And at last there is list of errors: 最后是错误列表:

http://www.w3.org/1999/xlink.xsd:27 : element import: Schemas parser warning : Element '{ http://www.w3.org/2001/XMLSchema }import': Skipping import of schema located at ' http://www.w3.org/2001/xml.xsd ' for the namespace ' http://www.w3.org/XML/1998/namespace ', since this namespace was already imported with the schema located at ' http://www.w3.org/2001/03/xml.xsd '. 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 '。
error : Operation in progress 错误:操作进行中
I/O warning : failed to load external entity " http://schemas.opengis.net/gml/3.1.1/base/coverage.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 : element include: Schemas parser error : Element '{ http://www.w3.org/2001/XMLSchema }include': Failed to load the document ' http://schemas.opengis.net/gml/3.1.1/base/coverage.xsd ' for inclusion. 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 ”。 error : Operation in progress 错误:操作进行中
I/O warning : failed to load external entity " http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd " I / O警告:无法加载外部实体“ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd
response.xml:3: element OAI-PMH: Schemas validity warning : Element '{ http://www.openarchives.org/OAI/2.0/ }OAI-PMH', attribute '{ http://www.w3.org/2001/XMLSchema-instance }schemaLocation': The document at location ' http://www.openarchives.org/OAI/2.0/OAI-PMH . 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' could not be acquired. 无法获取“ xsd”。
response.xml:3: element OAI-PMH: Schemas validity error : Element '{ http://www.openarchives.org/OAI/2.0/ }OAI-PMH': No matching global declaration available for the validation root. response.xml:3:元素OAI-PMH:架构有效性错误:元素'{ http://www.openarchives.org/OAI/2.0/ } OAI-PMH':没有匹配的全局声明可用于验证根。

Please help to find bug, I will be very pleasure! 请帮忙寻找bug,我将非常高兴!

The first set of error messages are complaining that the parser cannot grab download an external XSD file specified by its URL. 第一组错误消息抱怨解析器无法抓取其URL指定的外部XSD文件。

Is the box you're running this on able to access the Internet? 您正在运行的盒子是否可以访问Internet?

In order to be able to import external XSD file, there must be, naturally, Internet access. 为了能够导入外部XSD文件,自然必须具有Internet访问权限。

In absense of Internet access, it's possible to manually download any needed external files, and have them loaded locally, via the xml catalog file; 在没有Internet访问的情况下,可以手动下载任何所需的外部文件,并通过xml目录文件将其本地加载。 but that's a different, somewhat more complicated, topic. 但这是一个不同的,稍微复杂的话题。

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

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