我需要为XML文件生效XSD。
这是xml文件。
<?xml version="1.0" encoding="UTF-8"?>
<edge xmlns="http://www.example.org/flow">
<flowPara
style="letter-spacing:0px;fill:#000000;
font-size:9pt;font-family:Arial;text-anchor:start;text-align:start;"
id="textArea_38">
Text Flow checking and
<flowSpan style="fill:#FA0101; ">
font color change
text
<flowSpan style="fill:#C5A2A2; " />
</flowSpan>
in
<flowSpan
style="font-style:italic;letter-spacing:0px;fill:#000000;
font-size:9pt;font-family:Arial;text-anchor:start;text-align:start;">text
area
</flowSpan>
.
<flowSpan style="letter-spacing:0px;">
<flowSpan
style="text-decoration:underline;letter-spacing:0px;fill:#000000;
font-size:9pt;font-family:Arial;text-anchor:start;text-align:start;">Text
Flow
</flowSpan>
checking and
<flowSpan style="fill:#FA0101; ">
font color
change text
<flowSpan style="fill:#C5A2A2; ">
<flowSpan style="fill:#000000;
">in text area.</flowSpan>
</flowSpan>
</flowSpan>
</flowSpan>
</flowPara>
</edge>
这是我创建的XSD文件。
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/flow"
xmlns:tns="http://www.example.org/flow" elementFormDefault="qualified">
<element name="edge">
<complexType>
<sequence>
<element name="flowPara" maxOccurs="unbounded">
<complexType mixed="true">
<sequence>
<element name="flowspan" maxOccurs="unbounded">
<complexType mixed="true">
<sequence>
<element name="flowspan" maxOccurs="unbounded">
<complexType mixed="true">
<simpleContent>
<extension base="string">
<attribute name="style" type="string" />
</extension>
</simpleContent>
</complexType>
</element>
</sequence>
<attribute name="style" type="string" />
</complexType>
</element>
</sequence>
<attribute name="style" type="string" />
<attribute name="id" type="string" />
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>
我遇到了这种异常
异常:cvc-complex-type.2.4.b:元素'flowPara'的内容不完整。其中一个'{“http://www.example.org/flow”:flowspan}'是预期的。
答案 0 :(得分:3)
1)在您的架构中,您有几个地方flowspan
,s
为小写。将其更改为flowSpan
。
2)您声明了mixed
个内容,但您的flowSpan
元素不是可选的,因此如果flowSpan
的内容不包含,则始终是必需的,并且不会对其进行验证另一个flowSpan
。添加minOccurs="0"
,使其成为可选项。
3)如果您使用可选的嵌套flowSpan
混合内容,则无需声明简单内容。可以使用flowSpan
的引用重新组织您的模式,因为它是递归使用的。你可以试试这个:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/flow"
xmlns:tns="http://www.example.org/flow"
elementFormDefault="qualified">
<element name="edge">
<complexType>
<sequence>
<element name="flowPara" maxOccurs="unbounded">
<complexType mixed="true">
<sequence>
<element ref="tns:flowSpan" maxOccurs="unbounded"/>
</sequence>
<attribute name="style" type="string" />
<attribute name="id" type="string" />
</complexType>
</element>
</sequence>
</complexType>
</element>
<element name="flowSpan">
<complexType mixed="true">
<sequence>
<element ref="tns:flowSpan" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="style" type="string" />
</complexType>
</element>
</schema>
答案 1 :(得分:0)
你没有说minOccurs =&#39; 0&#39;,所以需要一个。