0

How can I use maxOccurs correctly in my code ?? I am getting error of repeating child. Thank you in advance

<xs:simpleType name="nameType">
<xs:restriction base="string">
<xs:minLength value="1" />
<xs:maxLength value="20" />
</xs:restriction>
</xs:simpleType>
<xs:element name="information">
<xs:complexType>
<xs:sequence>
<xs:element name="personal" maxOccurs="10">
<xs:complexType>
<xs:sequence>
<xs:element type="nameType" name="name"/>
<xs:element type="nameType" name="surname"/>
<xs:element type="nameType" name="age"/>
<xs:element type="nameType" name="postcode"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="school" maxOccurs="10">
<xs:complexType>
<xs:sequence>
<xs:element type="nameType" name="maths"/>
<xs:element type="nameType" name="english"/>
<xs:element type="nameType" name="physics"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
2
Contributors
7
Replies
35
Views
2 Years
Discussion Span
Last Post by rubberman
0

I assume there is a start node for <xs:schema>? Also, please properly indent the nodes. It helps to find such problems. In any case, this should be ok. What happens if you take the maxOccurs parameter out of the elements?

0

If i take the patameter everything works fine. To add i have my xml written in c i just need maxoccurs becuase i want my program to loop multiple times

0

No problem. New posters often make that mistake. The biggest problem with multiple posts is that one person will answer one, and another person will answer another. That dilutes the amount of help you will get since we can work off the comments and posts of others to get you the best results.

So, you are using this xml schema in a C program? Then am I correct to assume that this error occurs in the program? Can you post your code here that uses the XML file?

BTW, here is your code indented:

<xs:schema>
    <xs:simpleType name="nameType">
        <xs:restriction base="string">
            <xs:minLength value="1" />
            <xs:maxLength value="20" />
        </xs:restriction>
    </xs:simpleType>
    <xs:element name="information">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="personal" maxOccurs="10">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element type="nameType" name="name"/>
                            <xs:element type="nameType" name="surname"/>
                            <xs:element type="nameType" name="age"/>
                            <xs:element type="nameType" name="postcode"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="school" maxOccurs="10">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element type="nameType" name="maths"/>
                            <xs:element type="nameType" name="english"/>
                            <xs:element type="nameType" name="physics"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Edited by rubberman

0

My C code is working correctly, XML is written is a for loop so I have loop invariant in a program. If I loop C code only once the above XML Schema works - but without maxOccurs. I tried re-writing code many times, but nothing works. Thank you for indentation my code. Really appreciate your time

0

So, post your C code and I can probably help you solve this conundrum. I have been using XML and C/C++ for over 15 years.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.