xsd - XML validation for empty decimal element with precision attribute -


i have issue validating empty element against xsd contains definition below. if total_amt comes out empty, want empty element in xml document,

<total_amt/> 

so have created custom datatype in xsd shown below:

<xs:simpletype name="decimal-or-empty">   <xs:union membertypes="xs:decimal empty-string" /> </xs:simpletype>  <xs:simpletype name="empty-string">   <xs:restriction base="xs:string">     <xs:enumeration value="" />   </xs:restriction> </xs:simpletype> 

and xsd definition of element shown below.

<xs:element name = "total_amt"              nillable="false"              minoccurs="0"              type="decimal-or-empty">      <xs:complextype>        <xs:simplecontent>          <xs:extension base="xs:decimal">             <xs:attribute name="precision"                            type="xs:integer"/>         </xs:extension>       </xs:simplecontent>    </xs:complextype> </xs:element> 

if remove precision attribute in above xsd, validates custom data type , works empty value

<xs:element name = "total_amt"              nillable="false"              minoccurs="0"              type="decimal-or-empty"> </xs:element> 

but when define precision attribute, result xml instance invalid.

so, can please me in writing xsd can put precision attribute , still validate xml when value of total_amt empty?

your complex type adds precision attribute xs:decimal:

<xs:extension base="xs:decimal">   <xs:attribute name="precision"                  type="xs:integer"/> </xs:extension> 

why not add decimal-or-empty instead?

<xs:extension base="decimal-or-empty">   <xs:attribute name="precision"                  type="xs:integer"/> </xs:extension> 

that is, don't think it's presence of attribute declaration that's causing problem: it's union type no longer used.

you might consider using xsi:nil instead, though requires empty element

<total_amt xsi:nil="true"/> 

instead of just

<total_amt/> 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -