Why am I getting different results using two diffe

2019-09-01 13:02发布

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]|[À-Ö]|[Ø-ö]|[ø-˿]|[Ͱ-ͽ]|[Ϳ-῿]|[-]|[⁰-↏]|[Ⰰ-⿯]|[、-퟿]|[豈-﷏]|[ﷰ-�]|[                

4条回答
smile是对你的礼貌
2楼-- · 2019-09-01 13:11

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.

查看更多
手持菜刀,她持情操
3楼-- · 2019-09-01 13:15

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.

查看更多
爷的心禁止访问
4楼-- · 2019-09-01 13:18

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

查看更多
乱世女痞
5楼-- · 2019-09-01 13:31

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.

查看更多
登录 后发表回答