Вопрос

I need to valid XSD for a XML file.

This is xml file.

<?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> 

This is XSD file which i created .

<?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>

i faced this kind of exception

Exception: cvc-complex-type.2.4.b: The content of element 'flowPara' is not complete. One of '{"http://www.example.org/flow":flowspan}' is expected.

Это было полезно?

Решение

1) In your schema, you have flowspan with the s in lowercase in several places. Change that to flowSpan.

2) You declared mixed content, but your flowSpan element is not optional, so it will always be required and will not validate it if the contents of flowSpan don't contain another flowSpan. Add minOccurs="0" so it becomes optional.

3) You don't need to declare simple content if you have mixed content with an optional nested flowSpan. Your schema could be reorganized using a reference for flowSpan, since it's used recursively. You could try this:

<?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>

Другие советы

You didn't say minOccurs='0', so it requires one.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top