【问题标题】:xml schema validation error “The content of element 'flowPara' is not complete”xml 架构验证错误“元素 'flowPara' 的内容不完整”
【发布时间】:2014-03-18 12:26:58
【问题描述】:

我需要对 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}' 之一。

【问题讨论】:

    标签: java xml xsd xsd-validation


    【解决方案1】:

    1) 在您的架构中,您的 flowspans 在几个地方都是小写的。将其更改为 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>
    

    【讨论】:

      【解决方案2】:

      你没有说 minOccurs='0',所以它需要一个。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-29
        • 2013-11-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-17
        相关资源
        最近更新 更多