capdragon
capdragon

Reputation: 14899

how do schema validators know where to find the xsd associated with the namespace in xmlns?

I'm calling an external (3rd party) web service which is returning xml containing namespaces like such:

...
  xmlns:gml="http://www.opengis.net/gml"
  xmlns:wrs="http://www.opengis.net/cat/wrs/1.0"
  xmlns:rim="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0"
...

I'm interested in the last namespace that starts with urn:oasis.

how do validators know how to validate the file if there is no location specified?

I know the first ones don't have location specified either as they are just a namespace.

Could you elaborate on the following statement made in this article:

use URNs if your organization has a means of managing and resolving a suitable class of URN

How do these validators work without locations?

Upvotes: 1

Views: 237

Answers (1)

Vincent Biragnet
Vincent Biragnet

Reputation: 2998

To specify a schema location for validation purposes, you have different approaches :

With XML Schema :

  1. you tell your parser wich schema you want to use for validation (all implementations I know propose such mechanism). During the process, schema will be resolved given the namespaces in the instance. No need here to change your XML file.
  2. You add information about schemas location in your XML file.

For this second case, you have to use the following namespace : xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance". In this namespace, you have two attributes dedicated to validation : schemaLocation and noNamespaceSchemaLocation.

  1. If you don't have any namespaces, use the second (it's not your case).
  2. If you have namespaces, you use schemaLocation with the following syntax : xsi:schemaLocation="namespaceURI1 linkToTheSchema1 namespaceURI2 linkToTheSchema2...". Each schema declaration is composed of 2 parts separated with a space character: the namespace and the URI that pointed to the file.

With other schema langages (Relax NG, schematron)

  1. You can always use the first point above : telling your implementation with schema you want to use.

  2. In the XML file : W3C has published a note already implemented in some XML IDE that allows to add a processiog instruction called xml-model to give access to shcemas. See here : http://www.w3.org/TR/xml-model/.

Upvotes: 2

Related Questions