<fun xmlns="http://ttdi.us/I/am/having/fun"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ttdi.us/I/am/having/fun
test.xsd">
<activity>rowing</activity>
<activity>eating</activity>
<activity>coding</activity>
</fun>
使用以下XSD(诚然,我只是一个凡人):
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://ttdi.us/I/am/having/fun" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://ttdi.us/I/am/having/fun">
<xsd:element name="fun" type="activityList"></xsd:element>
<xsd:complexType name="activityList">
<xsd:sequence>
<xsd:element name="activity" type="xsd:string" maxOccurs="unbounded" minOccurs="0"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
cvc-complex-type.2.4.a: Invalid content was found starting with element 'activity'. One of '{activity}' is expected.
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://ttdi.us/I/am/having/fun"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://ttdi.us/I/am/having/fun">
<xsd:element name="activity" type="xsd:string"></xsd:element>
<xsd:element name="fun">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="activity" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<actvity>
在我的文档的根?如果
ref
应该按原样替换,那么为什么我不能替换
ref="actvity"
name="activity" type="xsd:string"
DocumentBuilderFactory dbf;
// initialize dbf
dbf.setNamespaceAware(true);