Why am I getting different results using two different ways of validating my XML?

冷暖自知 提交于 2019-12-12 01:43:09

问题


I'm trying to validate an XML file with an XSD file, which doesn't work and I don't know why.

I figured out that we could do it on terminal with that example :

xmllint --noout --schema owl2-xml.xsd camera.owl

But it produces an error, which I particularly don't understand.

regexp error : failed to compile: expecting a branch after |
owl2-xml.xsd:30: element pattern: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}pattern': The value '([A-Z]|[a-z]|[À-Ö]|[Ø-ö]|[ø-˿]|[Ͱ-ͽ]|[Ϳ-῿]|[-]|[⁰-↏]|[Ⰰ-⿯]|[、-퟿]|[豈-﷏]|[ﷰ-�]|[𐀀-󯿿])(([A-Z]|[a-z]|[À-Ö]|[Ø-ö]|[ø-˿]|[Ͱ-ͽ]|[Ϳ-῿]|[-]|[⁰-↏]|[Ⰰ-⿯]|[、-퟿]|[豈-﷏]|[ﷰ-�]|[𐀀-󯿿]|_|\-|[0-9]|·|[̀-ͯ]|[‿-⁀]|\.)*([A-Z]|[a-z]|[À-Ö]|[Ø-ö]|[ø-˿]|[Ͱ-ͽ]|[Ϳ-῿]|[-]|[⁰-↏]|[Ⰰ-⿯]|[、-퟿]|[豈-﷏]|[ﷰ-�]|[𐀀-󯿿]|_|\-|[0-9]|·|[̀-ͯ]|[‿-⁀]  ))?|' of the facet 'pattern' is not a valid regular expression.
WXS schema owl2-xml.xsd failed to compile

But if I choose a validator xml file (this one : http://mowl-power.cs.man.ac.uk:8080/validator/)

My XML file is validated !

I don't understand why, this isn't working ... When the XML Schema I'm choosing (should be) the same as the validator link.

The XML schema is from there : http://www.w3.org/2009/09/owl2-xml.xsd (owl2) And the validator also use the owl2 structure. So... What am i missing ?

Example Owl File

This is the example which i'm using and trying to validate camera.owl


回答1:


There are a number of ways that you can serialize an OWL ontology. One of them is to serialize it as RDF. RDF can also be serialized in a number of different formats, one of which is RDF/XML. Many of the files that you see online with a .owl extension are the RDF/XML serialization of the RDF representation of an OWL ontology. There's going to be lots of variation in the possibilities there, because the same RDF graph can be serialized in many different ways in the RDF/XML serialization. See my answer to How to access OWL documents using XPath in Java? for more about that issue.

Another way to serialize OWL ontologies is using the OWL/XML serialization, which is also XML based, but is not an RDF-based serialization. I'm assuming that you got the XSD file that you're using from 3.4 The XML Schema from OWL 2 Web Ontology Language XML Serialization (Second Edition). That serialization is a direct serialization of an OWL ontology in XML that doesn't take the OWL → RDF → RDF/XML route. That is, the XSD is for the OWL/XML format, not for RDF/XML.

So, I suspect that what's happening, regardless of whether or not your validator is handling the XSD correctly, is that you're attempting to validate an RDF/XML file using an XSD for OWL/XML. You didn't show any of the content of the OWL file that you're trying to validate though, so we can't be sure.

As a very simple example, here's a small OWL ontology in the OWL/XML serialization, generated though Protégé. This is what you get if you save the ontology using the OWL/XML format:

<?xml version="1.0"?>
<!DOCTYPE Ontology [
    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY xml "http://www.w3.org/XML/1998/namespace" >
    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>
<Ontology xmlns="http://www.w3.org/2002/07/owl#"
     xml:base="https://stackoverflow.com/q/23984040/1281433/example"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:xml="http://www.w3.org/XML/1998/namespace"
     ontologyIRI="https://stackoverflow.com/q/23984040/1281433/example">
    <Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
    <Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
    <Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
    <Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
    <Declaration>
        <Class IRI="#Person"/>
    </Declaration>
    <Declaration>
        <NamedIndividual IRI="#RichardNixon"/>
    </Declaration>
    <ClassAssertion>
        <Class IRI="#Person"/>
        <NamedIndividual IRI="#RichardNixon"/>
    </ClassAssertion>
    <AnnotationAssertion>
        <AnnotationProperty abbreviatedIRI="rdfs:label"/>
        <IRI>#RichardNixon</IRI>
        <Literal xml:lang="en" datatypeIRI="&rdf;PlainLiteral">Richard Nixon</Literal>
    </AnnotationAssertion>
</Ontology>
<!-- Generated by the OWL API (version 3.2.5.1912) http://owlapi.sourceforge.net -->

If you save the same ontology as RDF/XML, you get this:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns="https://stackoverflow.com/q/23984040/1281433/example#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
  <owl:Ontology rdf:about="https://stackoverflow.com/q/23984040/1281433/example"/>
  <owl:Class rdf:about="https://stackoverflow.com/q/23984040/1281433/example#Person"/>
  <owl:NamedIndividual rdf:about="https://stackoverflow.com/q/23984040/1281433/example#RichardNixon">
    <rdf:type rdf:resource="https://stackoverflow.com/q/23984040/1281433/example#Person"/>
    <rdfs:label xml:lang="en">Richard Nixon</rdfs:label>
  </owl:NamedIndividual>
</rdf:RDF>

They're both XML-based serializations of the ontology, but they're not the same, and only the OWL/XML representation would be validated by the XSD that you're using. Both could be validated using an OWL validator, though, because they're both legitimate serializations of an OWL ontology.




回答2:


The validator on mowl-power validates a file as an owl 2 ontology, not as XML. DTD and xsd resolution is usually switched off for the OWLAPI parsers it uses, I believe.




回答3:


xmllint's regular-expression parser appears to be in error. As the error message makes clear, it's expecting that the branch separator | will be followed by some non-empty branch; the XSD spec, however, is clear that the empty string counts as a branch. If you want to validate your XML against this XSD schema, you will need to use a validator with a more reliable implementation of XSD.




回答4:


You can use http://pythonhosted.org/Owlready/ to read and parse owl file before your code



来源:https://stackoverflow.com/questions/23984040/why-am-i-getting-different-results-using-two-different-ways-of-validating-my-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!