Rectangle 27 1

xsd what is the use of xsi:schemaLocation?


@HDave But what would XML parser be looking for, schema could have any name

@skaffman, Does it mean that when I run maven build of spring-based projhect with -o (offline) flag the build will fail despite the fact that all the dependencies are available in my local repository?

If you omit the schemaLocation, then the XML parser won't know where to get the schema in order to validate the config.

Technically, the XML parser will firstly try to load the schema from internet, if not found or internet access is not available, it will search *.xsd file locally from class path, if still not found, it will be omitted.

The Java XML parser that spring uses will read the schemaLocation values and try to load them from the internet, in order to validate the XML file. Spring, in turn, intercepts those load requests and serves up versions from inside its own JAR files.

Wouldn't the XML parser search the class path?

Note
Rectangle 27 1

xsd what is the use of xsi:schemaLocation?


An xmlns is a unique identifier within the document - it doesn't have to be a URI to the schema:

XML namespaces provide a simple method for qualifying element and attribute names used in Extensible Markup Language documents by associating them with namespaces identified by URI references.

can be used in a document to provide hints as to the physical location of schema documents which may be used for assessment.

xsi:schemaLocation is supposed to give a hint as to the actual schema location:

Note
Rectangle 27 1

xsd what is the use of xsi:schemaLocation?


@HDave But what would XML parser be looking for, schema could have any name

@skaffman, Does it mean that when I run maven build of spring-based projhect with -o (offline) flag the build will fail despite the fact that all the dependencies are available in my local repository?

If you omit the schemaLocation, then the XML parser won't know where to get the schema in order to validate the config.

Technically, the XML parser will firstly try to load the schema from internet, if not found or internet access is not available, it will search *.xsd file locally from class path, if still not found, it will be omitted.

The Java XML parser that spring uses will read the schemaLocation values and try to load them from the internet, in order to validate the XML file. Spring, in turn, intercepts those load requests and serves up versions from inside its own JAR files.

Wouldn't the XML parser search the class path?

Note
Rectangle 27 1

xsd what is the use of xsi:schemaLocation?


@HDave But what would XML parser be looking for, schema could have any name

@skaffman, Does it mean that when I run maven build of spring-based projhect with -o (offline) flag the build will fail despite the fact that all the dependencies are available in my local repository?

If you omit the schemaLocation, then the XML parser won't know where to get the schema in order to validate the config.

Technically, the XML parser will firstly try to load the schema from internet, if not found or internet access is not available, it will search *.xsd file locally from class path, if still not found, it will be omitted.

The Java XML parser that spring uses will read the schemaLocation values and try to load them from the internet, in order to validate the XML file. Spring, in turn, intercepts those load requests and serves up versions from inside its own JAR files.

Wouldn't the XML parser search the class path?

Note
Rectangle 27 1

xsd what is the use of xsi:schemaLocation?


Another wrinkle here is that typically, with xsd validation in java libraries [ex: spring config xml files], if your XML files specifies a particular schemaLocation xsd url in an XML file, like xsi:schemaLocation="http://somewhere http://somewhere/something.xsd" typically within one of your dependency jars it will contain a copy of that xsd file, in its resources section, and spring has a "mapping" capability saying to treat that xsd file as if it maps to the url http://somewhere/something.xsd (so you never end up going to web and downloading the file, it just exists locally). See also https://stackoverflow.com/a/41225329/32453 for slightly more info.

So basically with specifying just a namespace, your XML "might" be attempted to be validated against an xsd at that location (even if it lacks a schemaLocation attribute), depending on your "community." If you specify a specific schemaLocation, then it basically is implying that the xml document "should" be conformant to said xsd, so "please validate it" (as I read it). My guess is that if you don't do a schemaLocation or noNamespaceSchemaLocation attribute it just "isn't validated" most of the time (based on the other answers, appears java does it this way).

and

in case a document author (human or not) created a document with a particular schema in view, and warrants that some or all of the document conforms to that schema, the schemaLocation and noNamespaceSchemaLocation [attributes] are provided.

there may or may not be a schema retrievable via the namespace name... User community and/or consumer/provider agreements may establish circumstances in which [trying to retrieve an xsd from the namespace url] is a sensible default strategy

Note
Rectangle 27 1

xsd what is the use of xsi:schemaLocation?


Another wrinkle here is that typically, with xsd validation in java libraries [ex: spring config xml files], if your XML files specifies a particular schemaLocation xsd url in an XML file, like xsi:schemaLocation="http://somewhere http://somewhere/something.xsd" typically within one of your dependency jars it will contain a copy of that xsd file, in its resources section, and spring has a "mapping" capability saying to treat that xsd file as if it maps to the url http://somewhere/something.xsd (so you never end up going to web and downloading the file, it just exists locally). See also https://stackoverflow.com/a/41225329/32453 for slightly more info.

So basically with specifying just a namespace, your XML "might" be attempted to be validated against an xsd at that location (even if it lacks a schemaLocation attribute), depending on your "community." If you specify a specific schemaLocation, then it basically is implying that the xml document "should" be conformant to said xsd, so "please validate it" (as I read it). My guess is that if you don't do a schemaLocation or noNamespaceSchemaLocation attribute it just "isn't validated" most of the time (based on the other answers, appears java does it this way).

and

in case a document author (human or not) created a document with a particular schema in view, and warrants that some or all of the document conforms to that schema, the schemaLocation and noNamespaceSchemaLocation [attributes] are provided.

there may or may not be a schema retrievable via the namespace name... User community and/or consumer/provider agreements may establish circumstances in which [trying to retrieve an xsd from the namespace url] is a sensible default strategy

Note
Rectangle 27 1

xsd what is the use of xsi:schemaLocation?


Another wrinkle here is that typically, with xsd validation in java libraries [ex: spring config xml files], if your XML files specifies a particular schemaLocation xsd url in an XML file, like xsi:schemaLocation="http://somewhere http://somewhere/something.xsd" typically within one of your dependency jars it will contain a copy of that xsd file, in its resources section, and spring has a "mapping" capability saying to treat that xsd file as if it maps to the url http://somewhere/something.xsd (so you never end up going to web and downloading the file, it just exists locally). See also https://stackoverflow.com/a/41225329/32453 for slightly more info.

So basically with specifying just a namespace, your XML "might" be attempted to be validated against an xsd at that location (even if it lacks a schemaLocation attribute), depending on your "community." If you specify a specific schemaLocation, then it basically is implying that the xml document "should" be conformant to said xsd, so "please validate it" (as I read it). My guess is that if you don't do a schemaLocation or noNamespaceSchemaLocation attribute it just "isn't validated" most of the time (based on the other answers, appears java does it this way).

and

in case a document author (human or not) created a document with a particular schema in view, and warrants that some or all of the document conforms to that schema, the schemaLocation and noNamespaceSchemaLocation [attributes] are provided.

there may or may not be a schema retrievable via the namespace name... User community and/or consumer/provider agreements may establish circumstances in which [trying to retrieve an xsd from the namespace url] is a sensible default strategy

Note
Rectangle 27 1

xsd what is the use of xsi:schemaLocation?


@HDave But what would XML parser be looking for, schema could have any name

@skaffman, Does it mean that when I run maven build of spring-based projhect with -o (offline) flag the build will fail despite the fact that all the dependencies are available in my local repository?

If you omit the schemaLocation, then the XML parser won't know where to get the schema in order to validate the config.

Technically, the XML parser will firstly try to load the schema from internet, if not found or internet access is not available, it will search *.xsd file locally from class path, if still not found, it will be omitted.

The Java XML parser that spring uses will read the schemaLocation values and try to load them from the internet, in order to validate the XML file. Spring, in turn, intercepts those load requests and serves up versions from inside its own JAR files.

Wouldn't the XML parser search the class path?

Note
Rectangle 27 1

xsd what is the use of xsi:schemaLocation?


An xmlns is a unique identifier within the document - it doesn't have to be a URI to the schema:

XML namespaces provide a simple method for qualifying element and attribute names used in Extensible Markup Language documents by associating them with namespaces identified by URI references.

can be used in a document to provide hints as to the physical location of schema documents which may be used for assessment.

xsi:schemaLocation is supposed to give a hint as to the actual schema location:

Note
Rectangle 27 1

xsd what is the use of xsi:schemaLocation?


Another wrinkle here is that typically, with xsd validation in java libraries [ex: spring config xml files], if your XML files specifies a particular schemaLocation xsd url in an XML file, like xsi:schemaLocation="http://somewhere http://somewhere/something.xsd" typically within one of your dependency jars it will contain a copy of that xsd file, in its resources section, and spring has a "mapping" capability saying to treat that xsd file as if it maps to the url http://somewhere/something.xsd (so you never end up going to web and downloading the file, it just exists locally). See also https://stackoverflow.com/a/41225329/32453 for slightly more info.

So basically with specifying just a namespace, your XML "might" be attempted to be validated against an xsd at that location (even if it lacks a schemaLocation attribute), depending on your "community." If you specify a specific schemaLocation, then it basically is implying that the xml document "should" be conformant to said xsd, so "please validate it" (as I read it). My guess is that if you don't do a schemaLocation or noNamespaceSchemaLocation attribute it just "isn't validated" most of the time (based on the other answers, appears java does it this way).

and

in case a document author (human or not) created a document with a particular schema in view, and warrants that some or all of the document conforms to that schema, the schemaLocation and noNamespaceSchemaLocation [attributes] are provided.

there may or may not be a schema retrievable via the namespace name... User community and/or consumer/provider agreements may establish circumstances in which [trying to retrieve an xsd from the namespace url] is a sensible default strategy

Note