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>

Recommended Answers

All 7 Replies

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?

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

And yes there is a start tag for schema

I will remove the other post sorry about it

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>

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.