我经历了几个教程,但我无法像我想的那样使用我的XSD导入..请帮助我。
这是我的xml
<?xml version="1.0" encoding="UTF-8"?>
<mail>
<portalname>rezbase_v3</portalname>
<portalcolor1>'#b0b8da'</portalcolor1>
<portalcolor2>#0a1e75</portalcolor2>
<portalcolor3> '#333333'</portalcolor3>
<portalcolor4> '#e7eaf7'</portalcolor4>
<portalcolorfont1> '#bcc9ff'</portalcolorfont1>
<portalcolorfont2> '#000000'</portalcolorfont2>
</mail>
我对门户样式分开了xsd,看起来像这样(StyleApplyerDetailsBuilder.xsd)
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://NamespaceTest.com/StyleApplyerDetailsBuilder" elementFormDefault="qualified" >
<xs:group name="colors">
<xs:sequence>
<xs:element name="portalcolor1" type="xs:string"/>
<xs:element name="portalcolor2" type="xs:string"/>
<xs:element name="portalcolor3" type="xs:string"/>
<xs:element name="portalcolor4" type="xs:string"/>
<xs:element name="portalcolorfont1" type="xs:string"/>
<xs:element name="portalcolorfont2" type="xs:string"/>
</xs:sequence>
</xs:group>
</xs:schema>
我的主要xsd是这样的(main.xsd)
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="../../xsdFactory/commons/StyleApplyerDetailsBuilder.xsd"/>
<xs:element name="mail">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="portalname"></xs:element>
<!-- I need to import my other xsd(StyleApplyerDetailsBuilder) to here so I can validate my xml -->
<xs:group ref="colors" maxOccurs="unbounded" minOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我需要的是将StyleApplyerDetailsBuilder.xsd导入main.xsd并验证上面的xml。
答案 0 :(得分:1)
您可以使用
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="StyleApplyerDetailsBuilder.xsd"/>
<xs:element name="mail">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="portalname"></xs:element>
<!-- I need to import my other xsd(StyleApplyerDetailsBuilder) to here so I can validate my xml -->
<xs:element ref="portalcolor1"/>
<xs:element ref="portalcolor2"/>
<!-- reference the other elements here -->
</xs:sequence>
</xs:complexType>
</xs:element>
通常你会定义一个组和引用,例如在要包含的样式表中定义
<xs:group name="colors">
<xs:sequence>
<xs:element name="portalcolor1" type="xs:string"/>
<xs:element name="portalcolor2" type="xs:string"/>
<xs:element name="portalcolor3" type="xs:string"/>
<xs:element name="portalcolor4" type="xs:string"/>
<xs:element name="portalcolorfont1" type="xs:string"/>
<xs:element name="portalcolorfont2" type="xs:string"/>
</xs:sequence>
</xs:group>
然后你使用如图所示的include,而不是所有对你使用的不同元素的引用
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="StyleApplyerDetailsBuilder.xsd"/>
<xs:element name="mail">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="portalname"></xs:element>
<!-- I need to import my other xsd(StyleApplyerDetailsBuilder) to here so I can validate my xml -->
<xs:group ref="colors"/>
</xs:sequence>
</xs:complexType>
</xs:element>