1

I have this xml:

<?xml version="1.0"?>
<itens_pedidos xmlns="www.example.org" 
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xsi:schemaLocation="www.example.org ex1.xsd">
    <item>
        <produto>caneta azul</produto>
        <quantidade>100</quantidade>
        <preco_unit>2</preco_unit>
    </item>
    <item>
        <produto>caneta preta</produto>
        <quantidade>200</quantidade>
        <preco_unit>3.5</preco_unit>
    </item>
</itens_pedidos>

and this xml schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns="www.example.org" 
    targetNamespace="www.example.org">
    <xs:element name="itens_pedidos">
        <xs:complexType>
            <xs:sequence>

                <xs:element name="item" minOccurs="2" maxOccurs="unbounded">
                    <xs:complexType>
                        <xs:sequence>

                            <xs:element name="produto" type="xs:string"/>
                            <xs:element name="quantidade" type="xs:integer"/>
                            <xs:element name="preco_unit" type="xs:decimal"/>

                        </xs:sequence>
                    </xs:complexType>
                </xs:element>

            </xs:sequence>
        </xs:complexType>
    </xs:element>

 </xs:schema>

and i get this error when i try to validate the xml and xsd:

Not valid. Error - Line 3, 11: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 11; cvc-complex-type.2.4.a: Invalid content was found starting with element 'item'. One of '{item}' is expected.

i still don't get why it is happening if someone can explain it to me i appreciate a lot :D

C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65
  • Not well formed: Content is not allowed in trailing section. –  Feb 02 '17 at 21:10
  • So, what would you like to tell me? What did you do? What should I do? – Mathias Müller Feb 02 '17 at 21:12
  • well i added the content in the schema tag, but i got that error :S –  Feb 02 '17 at 21:25
  • In [another answer](http://stackoverflow.com/a/42010695/1987598), @kjhughes has shown you 2 hours ago how to use `elementFormDefault="qualified"`. Where did you put it? Did you make any other changes to the XML document or schema? – Mathias Müller Feb 02 '17 at 21:27
  • seems like i must have all that info in the same line, i change it and worked, i was confused because i had everything, sorry and thank you friend, –  Feb 02 '17 at 21:33
  • this syntax is a bit strange, i always think it has something to do with the structure –  Feb 02 '17 at 21:34
  • No, you definitely do not need everything on the same line (but within / on the same element). But a stray `>` in the middle of an element will cause errors, for instance - as you now know. – Mathias Müller Feb 02 '17 at 21:36
  • awesome, thank you very much for your patience, but i am still trying to adapt xsd is a strange syntax :D –  Feb 02 '17 at 21:55

0 Answers0