d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Schema > How Do I Make This Work.
Add Reply New Topic New Poll
Member
Posts: 1,849
Joined: May 31 2008
Gold: 2,571.50
Apr 25 2014 05:39pm
Code
Error 1824: Element 'month': '' is not a valid value of the atomic type 'monthType'. in /tmp/phpmGaRxB on line 261 in column: 0

^Error from validating XML file against schema

In my xml document I have a - dateOfBirth(month,day,year) - this is an optional field, since these tags still exist even without values in them they will not pass validation. My schema requires them to be xsd:integer as well as have a inclusive range of a acceptable values.

I am not sure how to add a sort of exception to this, any help would be appreciated. Even if the help was pointing me where to find it on w3 or a similar post on stack overflow that could help.

If your post helped me fix this error, I am more than willing to give a fg donation! Thanks for time, if my wording is poor and needs clarification don't be afraid to ask me to provide more details.

This post was edited by Noobtard on Apr 25 2014 05:40pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Apr 25 2014 05:41pm
minOccurs="0" maxOccurs="1"

best thing to do is post your schema and two samples of your xml: one with the field, one without, where both should validate. but if i understand you correctly, the above should solve your problem by allowing your field to be missing

This post was edited by carteblanche on Apr 25 2014 05:43pm
Member
Posts: 1,849
Joined: May 31 2008
Gold: 2,571.50
Apr 25 2014 05:45pm
Quote (carteblanche @ Apr 25 2014 06:41pm)
minOccurs="0" maxOccurs="1"


^ I have this already - I think by minOccurs="0" it refers to there can be a minimum of 0 tags in the XML. Since the tags still exist in my XML (but are just emptied) - it doesn't like this i think because its not a 'xsd:integer'

When the empty tags in the XML are commented out - it passes validation. I've included a little bit of the schema below - just to help clarify what I currently have.

Code
<xsd:element name="dateOfBirth" type="dateOfBirthType" minOccurs="0" maxOccurs="1"/>


Code
<xsd:complexType name="dateOfBirthType">
<xsd:sequence>
<xsd:element name="month" type="monthType"/>
<xsd:element name="day" type="dayType"/>
<xsd:element name="year" type="yearType"/>
</xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="monthType">
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="1"/>
<xsd:maxInclusive value="12"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="dayType">
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="1"/>
<xsd:maxInclusive value="31"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="yearType">
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="1800"/>
<xsd:maxInclusive value="2100"/>
</xsd:restriction>
</xsd:simpleType>


This post was edited by Noobtard on Apr 25 2014 05:53pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Apr 25 2014 06:03pm
Quote (Noobtard @ Apr 25 2014 07:45pm)
^ I have this already - I think by minOccurs="0" it refers to there can be a minimum of 0 tags in the XML. Since the tags still exist in my XML (but are just emptied) - it doesn't like this i think because  its not a 'xsd:integer'

When the empty tags in the XML are commented out - it passes validation. I've included a little bit of the schema below - just to help clarify what I currently have.

Code
<xsd:element name="dateOfBirth" type="dateOfBirthType" minOccurs="0" maxOccurs="1"/>


Code
<xsd:complexType name="dateOfBirthType">
  <xsd:sequence>
  <xsd:element name="month" type="monthType"/>
  <xsd:element name="day" type="dayType"/>
  <xsd:element name="year" type="yearType"/>
  </xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="monthType">
  <xsd:restriction base="xsd:integer">
  <xsd:minInclusive value="1"/>
  <xsd:maxInclusive value="12"/>
  </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="dayType">
  <xsd:restriction base="xsd:integer">
  <xsd:minInclusive value="1"/>
  <xsd:maxInclusive value="31"/>
  </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="yearType">
  <xsd:restriction base="xsd:integer">
  <xsd:minInclusive value="1800"/>
  <xsd:maxInclusive value="2100"/>
  </xsd:restriction>
</xsd:simpleType>


maybe this one? nillable="true" or put in a default value

This post was edited by carteblanche on Apr 25 2014 06:24pm
Member
Posts: 1,849
Joined: May 31 2008
Gold: 2,571.50
Apr 25 2014 06:33pm
I tried the xsi:nil="true" -- with no sucess D:
I also tried <xsd:element name="month" type="monthType" nillable="true"/> -- no success


It seems to be only disliking the empty tags, in the xml (i gave a better illustration of xml below). Thanks btw for your speedy responses.

Code
<p1>
<dateOfBirth>
<month></month>
<day></day>
<year></year>
</dateOfBirth>
</p1>
<p2>
<dateOfBirth>
<month>01</month>
<day>02</day>
<year>1990</year>
</dateOfBirth>
</p2>


E* Going to try a default value
^ Tried - I can eliminate the errors by defaulting the value to a number that is within my min / max inclusive restrictions. Not sure if it would be the 'correct' way to change my minInclusive = 0 and default all those elements @ 0 to bypass... but not sure of other options.

This post was edited by Noobtard on Apr 25 2014 06:39pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Apr 25 2014 06:40pm
Quote (Noobtard @ Apr 25 2014 08:33pm)
I tried the xsi:nil="true" -- with no sucess D:
I also tried <xsd:element name="month" type="monthType" nillable="true"/> -- no success


It seems to be only disliking the empty tags, in the xml (i gave a better illustration of xml below). Thanks btw for your speedy responses.

Code
<p1>
              <dateOfBirth>
  <month></month>
  <day></day>
  <year></year>
  </dateOfBirth>
</p1>
<p2>
              <dateOfBirth>
  <month>01</month>
  <day>02</day>
  <year>1990</year>
  </dateOfBirth>
</p2>


E* Going to try a default value


xsi:nil="true" in your xml and nillable="true" in your xsd was intended for if you wanted to pass a null value to your app, which i realized wasnt what you intended. usually i just pass empty for strings and default a value for integers. but if you need it to be empty, you can try a union

http://www.ilearnttoday.com/xsd-empty-values-and-range-restriction-for-numeric-types
Member
Posts: 1,849
Joined: May 31 2008
Gold: 2,571.50
Apr 25 2014 07:02pm
Quote (carteblanche @ Apr 25 2014 07:40pm)
xsi:nil="true" in your xml and  nillable="true" in your xsd was intended for if you wanted to pass a null value to your app, which i realized wasnt what you intended. usually i just pass empty for strings and default a value for integers. but if you need it to be empty, you can try a union

http://www.ilearnttoday.com/xsd-empty-values-and-range-restriction-for-numeric-types


I fsdjmkfmksjfsjfksjfalkfjs lkfjslk LOVE YOU.... Validation = success.. enjoy the donation for your time! Thanks again...fjskfjslfkjas
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll