我有一个 xsd 来验证一个 xml 文件,但我收到了错误Invalid content was found starting with element 'user'. One of '{user}' is expected.
如果我将命名空间声明更改为xmlns:synchronisation="synchronisation"
并放置synchronisation:syncQueryMapping
为根标记,但其余部分保持不变,则它已被验证,但我不明白为什么这样做,为什么它是必要的以及为什么其余的标签不需要它.
我似乎无法理解并解决这个问题,所以任何帮助将不胜感激!
谢谢!
xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<syncQueryMapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="synchronisation"
xsi:schemaLocation="synchronisation syncQueryMappingSchema.xsd">
<user>
<tableName></tableName>
<nameColumn></nameColumn>
<passwordColumn></passwordColumn>
</user>
<group>
<tableName></tableName>
<nameColumn></nameColumn>
</group>
<userGroupMapping>
<tableName></tableName>
<userNameColumn></userNameColumn>
<groupNameColumn></groupNameColumn>
</userGroupMapping>
</syncQueryMapping>
xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="1.0" targetNamespace="synchronisation" xmlns="synchronisation">
<!-- JAXB Configuration -->
<xs:annotation>
<xs:appinfo>
<jaxb:schemaBindings>
<jaxb:package name="synchronisation.implementation" />
</jaxb:schemaBindings>
</xs:appinfo>
</xs:annotation>
<xs:complexType name="dbSyncUserType" >
<xs:sequence>
<xs:element type="xs:string" name="tableName" />
<xs:element type="xs:string" name="nameColumn" />
<xs:element type="xs:string" name="passwordColumn" />
<xs:element type="xs:string" name="suspendStartDateColumn" minOccurs="0" />
<xs:element type="xs:string" name="suspendEndDateColumn" minOccurs="0" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="dbSyncGroupType">
<xs:sequence>
<xs:element type="xs:string" name="tableName" />
<xs:element type="xs:string" name="nameColumn" />
<xs:element type="xs:string" name="typeColumn" minOccurs="0" />
<xs:element type="typeColumnDataTypeType" name="typeColumnDataType" minOccurs="0" />
<xs:element type="xs:string" name="typeValue" minOccurs="0" />
</xs:sequence>
</xs:complexType>
<xs:simpleType name="typeColumnDataTypeType">
<xs:restriction base="xs:string">
<xs:enumeration value="INTEGER" />
<xs:enumeration value="VARCHAR" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="dbSyncUserTableJoinType">
<xs:sequence>
<xs:element type="xs:string" name="userKeyColumn" />
<xs:element type="xs:string" name="mappingsForeignKeyColumn" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="dbSyncGroupTableJoinType">
<xs:sequence>
<xs:element type="xs:string" name="groupKeyColumn" />
<xs:element type="xs:string" name="mappingsForeignKeyColumn" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="dbSyncUserGroupMappingJoinType">
<xs:sequence>
<xs:element type="dbSyncUserTableJoinType" name="userTable" />
<xs:element type="dbSyncGroupTableJoinType" name="groupTable" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="dbSyncUserGroupMappingType">
<xs:sequence>
<xs:element type="xs:string" name="tableName" />
<xs:element type="xs:string" name="userNameColumn" />
<xs:element type="xs:string" name="groupNameColumn" />
<xs:element type="dbSyncUserGroupMappingJoinType" name="join" minOccurs="0" />
</xs:sequence>
</xs:complexType>
<!-- Root element -->
<xs:element name="syncQueryMapping">
<xs:complexType>
<xs:sequence>
<xs:element type="dbSyncUserType" name="user" />
<xs:element type="dbSyncGroupType" name="group" />
<xs:element type="dbSyncUserGroupMappingType" name="userGroupMapping" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>