Jump to content

Need Help With Xsd, Especially Namespaces/prefix


neigaard

Recommended Posts

HiI have some XML, that are a home made subset of OWL/RDF XML. I have some very specific rules, and I would like to make as much validation with XSD as possible. However I have failed even to make the simplest validation :)Here is a example of my XML:

<?xml version="1.0" encoding="UTF-8"?><rdf:RDF   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"  xmlns:owl="http://www.w3.org/2002/07/owl#">	<owl:Ontology rdf:about="">	<rdfs:comment>Must not be empty</rdfs:comment>	</owl:Ontology>		<owl:Class rdf:ID="XXX-id">		<rdfs:subClassOf rdf:resource="#YYY-id"></rdfs:subClassOf>	<rdfs:label>Term X</rdfs:label>	<rdfs:comment>Some comment X</rdfs:comment>	</owl:Class>		<owl:Class rdf:ID="YYY-id">	<rdfs:label>Term Y</rdfs:label>	<rdfs:comment>Some comment Y</rdfs:comment>	</owl:Class>		<owl:Class rdf:ID="ZZZ-id">		<owl:deprecated/>		<rdfs:subClassOf rdf:resource="#YYY-id"></rdfs:subClassOf>	<rdfs:label>Term Z</rdfs:label>	<rdfs:comment>Some comment Z</rdfs:comment>	</owl:Class></rdf:RDF>

Here are my rules: - The XML root element must be "rdf:RDF" - There must be one and only one "owl:Ontology" tag and it must contain one "rdfs:comment" tag and it must not be empty - There can be zero to many "owl:Class" tags - All "owl:Class" tags must contain a "rdfs:label" tag and it must not be empty - "owl:Class" tags can contain one "rdfs:subClassOf", "rdfs:comment" and "owl:deprecated" tags - There can be only one "owl:Class" that has no "rdfs:subClassOf" tag, which means only one root "owl:Class" - This does not apply to "owl:Class" tags containing a "<owl:deprecated/>" tag, as these "owl:Class" tags are not counted at valid - There must be no circular referencesI have read tutorials and what not, and I have tried several attempts, but I cant even get the basics to work. I do not know how to make a XSD that matches on the prefixes, so I cant even make it match a "rdf:RDF" tag??So any help will be greatly appriciated? Can I do all the validation I want with XSD, or do I have to some of it in code? How do I get started?Thank youSøren

Link to comment
Share on other sites

Just declare the namespaces inside the XSD file, then use them wherever a QName is expected. For example:

<xs:element name="rdf:RDF"/>

Would declare the rdf:RDF element, as long as you have

<xs:schema ... xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

at the top.

Link to comment
Share on other sites

Hm... I have no success. Here is my try:

<?xml version="1.0" encoding="UTF-8"?><xs:schema  xmlns:xs="http://www.w3.org/2001/XMLSchema"  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"  xmlns:owl="http://www.w3.org/2002/07/owl#"  elementFormDefault="qualified"><xs:element name="rdf:RDF">	<xs:complexType>		<xs:sequence>		  <xs:element name="owl:Ontology" type="xs:string">			<xs:complexType>				<xs:sequence>				  <xs:element name="rdfs:comment" type="xs:string"/>				</xs:sequence>			</xs:complexType>		  </xs:element>		  <xs:element name="owl:Class" type="xs:string">				  <xs:complexType>				<xs:sequence>				  <xs:element name="owl:deprecated" type="xs:string"/>				  <xs:element name="rdfs:subClassOf" type="xs:string"/>				  <xs:element name="rdfs:label" type="xs:string"/>				  <xs:element name="rdfs:comment" type="xs:string"/>				</xs:sequence>			</xs:complexType>			  </xs:element>		</xs:sequence>	</xs:complexType></xs:element></xs:schema>

I use Apache Xerces to parse the XML, and here is what I get:

org.xml.sax.SAXParseException: s4s-att-invalid-value: Invalid attribute value for 'name' in element 'element'. Recorded reason: cvc-datatype-valid.1.2.1: 'rdf:RDF' is not a valid value for 'NCName'.

Any ideas?Thank youSøren

Link to comment
Share on other sites

Hi,To check if there is empty tag in the xml file, we need to write code both in the xml file and the xsd:How to have an empty tag validated successfully against schema?1. In xsd file add this:<xs:element name="rdfs:comment" type="xs:string" nillable="false"/>2. In xml file add this:<rdfs:comment xsi:nil="false"/>Here the new keywords to be used to validate aganist an empty tag are nillable and xsi:nilRegards,Arunahttp://technologyandleadership.com/technology/

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...

I am sure that with those home made XML made subset of OWL/RDF XML, it will be possible to make as much validation with the XSD especially with all the rules and the codes given which will make it simpler to find out what exactly could have been done for it not to work!! I am sure that he’ll get the solution for his problem from the forum which will help him to continue with his work!!____________________Cloud Hosting

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...