Other answers are good here, so I will not repeat their explanations here. However, if anyone from Java background, find its simpler, here is the analogy I came up with -
.xsd
document is the artifact/.jar
file
xmlns
is the
package com.example
statement, you declare at the top of your Java classes.
Consider (for analogy), if you had one single package in your Java project, and all the classes are declared and defined within a single outer class.
For eg,
package com.furniture.models
public class FurnitureShop {
int noOfTables;
int noOfChairs;
int noOfBeds;
List<Table> tables;
List<Chair> chairs;
List<Bed> beds;
// and now instead of declaring and defining a class for table/chair/bed in a
// separate file, you just add it here
public static class Table {
int height;
int width;
int length;
...
}
public static class Chair {
String color;
ChairType chairType;
...
}
public static class Sofa {
int price;
String color;
...
}
}
This is how different elements are grouped in a single .xsd
file, for a new schema.
targetNamespace
is the name of the artifact you create. As you can find it out yourself, targetNamespace
is used when creating a schema, in an .xsd
file.
Once, the artifact(or .xsd
file) is created, you'd use it in other projects as follows -
In a Java project, you'd import the library, using pom.xml
(or build.gradle
) file as follows -
<dependency>
<groupId>com.furniture</groupId>
<artifactId>furniture-apis</artifactId>
<version>1.1.1</version>
</dependency>
In XML, you'd "import" the schema using
<furniture xmlns="http://furniture.com"/>
=== APPENDIX ===
Clarification -
xmlns
is both used as a package
statement, as well as the import
statement in Java. In .xsd
file, xmlns
acts as the "package
" statement, whereas in .xml
files, it acts as the "import
" statement.