其他回答已经很好了,所以我不会在这里重复它们的解释。然而,如果有来自Java背景的人发现这更简单,请看我想出来的类比:
Original Answer翻译成"最初的回答"
.xsd
document is the artifact/.jar
file
xmlns
is the
package com.example
statement, you declare at the top of your Java classes.
最初的回答:考虑一下(类比),如果您在Java项目中只有一个单一的包,并且所有的类都声明和定义在一个单独的外部类中。
例如,
package com.furniture.models
public class FurnitureShop {
int noOfTables;
int noOfChairs;
int noOfBeds;
List<Table> tables;
List<Chair> chairs;
List<Bed> beds;
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;
...
}
}
这就是在新模式下将不同元素组合在单个.xsd文件中的方法。
3. targetNamespace 是您创建的文件的名称。可以自己找出,当创建一个模式时,targetNamespace 用于在xsd文件中命名。
一旦创建了工件(或.xsd文件),您可以按以下方式在其他项目中使用它:
在Java项目中,您可以使用pom.xml(或build.gradle)文件导入库,如下所示:
<dependency>
<groupId>com.furniture</groupId>
<artifactId>furniture-apis</artifactId>
<version>1.1.1</version>
</dependency>
在XML中,你需要使用"import"来引入模式。最初的回答。
<furniture xmlns="http://furniture.com"/>
=== 附录 ===
澄清 -
xmlns
在Java中既用作package
语句,也用作import
语句。在.xsd
文件中,xmlns
充当"package
"语句,而在.xml
文件中,它充当"import
"语句。
注:Original Answer翻译成"最初的回答"