xml - How to add attribute on element level in xsd -
i want genearte kind of xml using xsd
<unassignedsecurityroleusers> <username errorcode= "1" errormessage="">?</username> <username errorcode= "1" errormessage="">?</username> .... .... </unassignedsecurityroleusers>
i tried first
<xsd:element name="unassignedsecurityroleusers" type="unassignedsecurityroleusers"/> <xsd:complextype name="unassignedsecurityroleusers"> <xsd:sequence> <xsd:element name="unassignedusers" type="unassignedusers" minoccurs="1" maxoccurs="unbounded" /> </xsd:sequence> </xsd:complextype> <xsd:element name="unassignedusers" type="unassignedusers"/> <xsd:complextype name="unassignedusers"> <xsd:sequence> <xsd:element name="username" type="xsd:string" minoccurs="1" maxoccurs="unbounded" /> </xsd:sequence> <xsd:attribute name="errorcode" type="xsd:string" /> <xsd:attribute name="errormessage" type="xsd:string" /> </xsd:complextype>
but generate this
<unassignedsecurityroleusers> <unassignedusers errorcode="" errormessage="" > <username></username> </unassignedusers> <unassignedusers errorcode="" errormessage="" > <username></username> </unassignedusers> ... .... </unassignedsecurityroleusers>
if use
<xsd:element name="unassignedsecurityroleusers" type="unassignedsecurityroleusers"/> <xsd:complextype name="unassignedsecurityroleusers"> <xsd:sequence> <xsd:element name="username" type="xsd:string" minoccurs="1" maxoccurs="unbounded" /> </xsd:sequence> <xsd:attribute name="errorcode" type="xsd:string" /> <xsd:attribute name="errormessage" type="xsd:string" /> </xsd:complextype>
then generate
<unassignedsecurityroleusers errorcode="" errormessage=""> <username></username> </unassignedsecurityroleusers>
how can generate using xsd
<unassignedsecurityroleusers> <username errorcode= "1" errormessage="">?</username> <username errorcode= "1" errormessage="">?</username> .... .... </unassignedsecurityroleusers>
thanks
if give username
element type="xsd:string"
can't have attributes. allow both text content and attributes need give element complextype
simplecontent
extends xsd:string
, , declare attributes on type rather on unassignedsecurityroleusers
type:
<xsd:element name="unassignedsecurityroleusers" type="unassignedsecurityroleusers"/> <xsd:complextype name="unassignedsecurityroleusers"> <xsd:sequence> <xsd:element name="username" minoccurs="1" maxoccurs="unbounded"> <xsd:complextype> <xsd:simplecontent> <xsd:extension base="xs:string"> <xsd:attribute name="errorcode" type="xsd:string" /> <xsd:attribute name="errormessage" type="xsd:string" /> </xsd:extension> </xsd:simplecontent> </xsd:complextype> </xsd:element> </xsd:sequence> </xsd:complextype>
if want able declare other elements same attributes use named complextype
instead of nesting inside username
element:
<xsd:complextype name="valuewitherror"> <xsd:simplecontent> <xsd:extension base="xs:string"> <xsd:attribute name="errorcode" type="xsd:string" /> <xsd:attribute name="errormessage" type="xsd:string" /> </xsd:extension> </xsd:simplecontent> </xsd:complextype> <xsd:complextype name="unassignedsecurityroleusers"> <xsd:sequence> <xsd:element name="username" minoccurs="1" maxoccurs="unbounded" type="valuewitherror"/> </xsd:sequence> </xsd:complextype>
Comments
Post a Comment