0

Hi I've changed my element type from xs:integer to xs:decimal, but when i try to validate my xml an error occurred: " '0.2' is not a valid value for 'integer'." I don't understand why the result type is integer yet. This is my xsd:

<?xml version="1.0" encoding="UTF-8"?>
   <xs:schema xmlns="https://www.w3schools.com" 
     xmlns:xs="http://www.w3.org/2001/XMLSchema" 
     targetNamespace="https://www.w3schools.com">

 <xs:element name="distribution">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="type" minOccurs="1" maxOccurs="1"/>
            <xs:element ref="value" minOccurs="1" maxOccurs="2"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>   

<xs:element name = "type">
    <xs:simpleType>
        <xs:restriction base="xs:string"/>
    </xs:simpleType>
</xs:element>

<xs:element name="value">
    <xs:simpleType>
        <xs:restriction base="xs:decimal"/>
    </xs:simpleType>
</xs:element>

And the xml I want to validate:

<?xml version="1.0" encoding="UTF-8"?>
<working xmlns="https://www.w3schools.com" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  xsi:noNamespaceSchemaLocation="processoproduttivo.xsd">

<resources> <!-- resources map-->
    <resource resourcename="A1">
        <resourcenumber>4</resourcenumber><!-- number of machines-->
        <capacity>50</capacity><!-- machine's capacity-->
        <distribution><!-- type of distribution-->
            <type>Uniform</type>
            <value>0.2</value>
            <value>4</value>
        </distribution>
    </resource>
</resources>
</working>
Hashet
  • 5
  • 1
  • 6
  • How do you do the validation? – m4gic Sep 14 '18 at 08:24
  • I use Notepad++ and https://www.corefiling.com/opensource/schemavalidate/. – Hashet Sep 14 '18 at 08:25
  • You should consider to use XmlSpy or Oxigen for editing and validating this sort of things. I think the most possible reason is that on the server uses a locale where a decimal number is serialized differently, e.g. 0,2 is a valid decimal for some locales, and of course these locales find 0.2 invalid. I saw similar problems in Java (however there xs:decimal would be mapped to java.math.BigDecimal, not Integer - and of course, the server is right, 0.2 is not an Integer :) ) – m4gic Sep 14 '18 at 08:29
  • btw, you can simplify your value def in this way: – m4gic Sep 14 '18 at 08:33
  • Another way of validating XMLs against XSDs in [Notepad++](https://stackoverflow.com/questions/15436183/using-notepad-to-validate-xml-against-an-xsd), maybe it will do a better job. – m4gic Sep 14 '18 at 08:36
  • Ok, I'll try. Thank you. – Hashet Sep 14 '18 at 08:36

1 Answers1

0

I don't think you are validating this document against this schema.

For a start, the namespaces don't match. Your schema is for namespace "https://www.w3schools.com" (which is bad practice, because I don't think you own that domain), but your instance appears to be in no namespace.

== UPDATE ==

You have now edited the question to show the full XML. This shows that the XML instance is indeed in the target namespace of the schema. However, it contains an xsi:noNamespaceSchemaLocation attribute which is only useful for validating no-namespace elements, and isn't going to help in finding schema declarations for an element in the "https://www.w3schools.com" namespace.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Hi I edit the first line of my xml. I don't know if you refer to its. Could you be more clear? – Hashet Sep 14 '18 at 10:51
  • So, how can I fix it? – Hashet Sep 17 '18 at 07:18
  • There are so many possible ways of finding a schema to use for validating a source document, and I have no idea what environment you are in or what your constraints are, so I can't advise you. – Michael Kay Sep 17 '18 at 14:21