72768

xml element enumerated attribute and enumerated value in xsd

Question:

Of interest is the following xml child element:

<optInItem type='MARKETING_EMAILS'>NO</optInItem>

I'd like to enumerate possible values (assume 2 possible values) for attribute 'type' and enumerate possible values for the text value of optInItem (values could be Yes | No). I am starting with the following xsd but am not sure how to add in the two separate enumerations.

<xs:element name="optInItem" maxOccurs="2" minOccurs="2"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute type="xs:string" name="type" use="required"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element>

Any suggestions/pointers would be appreciated.

thanks

Answer1:

After many iterations, it looks like the following does the trick:

<xs:element name="account"> <xs:complexType> <xs:sequence> <xs:element type="optInItemType" name="optInItem" maxOccurs="2" minOccurs="2"> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="optInItemType"> <xs:simpleContent> <xs:extension base="elementOptInItemType"> <xs:attribute name="type" type="attrOptInItemType"/> </xs:extension> </xs:simpleContent> </xs:complexType> <xs:simpleType name="elementOptInItemType"> <xs:restriction base="xs:string"> <xs:enumeration value="YES"/> <xs:enumeration value="NO"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="attrOptInItemType"> <xs:restriction base="xs:string"> <xs:enumeration value="MARKETING_EMAILS"/> <xs:enumeration value="UPDATE_NOTIFICATIONS"/> </xs:restriction> </xs:simpleType>

That was a more complicated than I thought it would be. The simpleContent extension base allowed a user defined type and thus was the key to pulling it all together.

Recommend

  • where does a typedef enum statement go in Objective-C?
  • Returning complex type response at BPEL
  • Co-Occurre​nce Constraint​
  • Unmarshalling works incorrectly: javax.xml.bind.UnmarshalException: unexpected element
  • What is the meaning of xs:mixed without elements?
  • minOccurs and maxOccurs on elements inside xsd:choice
  • Filtering SPARQL results by day and month
  • ELMAH: Can you set it up to email errors only remotely?
  • SQL Stored Procedure - variable too short
  • Sticky Footer W/JQuery Mobile
  • How to call BeanFactoryPostProcessor.postProcessBeanFactory method when use Spring with XML configur
  • iOS custom UTI in UIDocumentPickerViewController initWithDocumentTypes
  • HTML code to upload images
  • Configuring Ninject
  • button in popup.html not working
  • VB.NET 2012 Property Set on Property Get
  • c++ search a vector for element first seen position
  • Is there any purpose for h2-h6 headings in HTML5?
  • How to know which Linq statement produced the SQL on hand during runtime?
  • Easiest way to get current unix timestamp via XSL
  • How can I replace the server in Web Component Tester
  • How to convert SOAP response with xsi values to json in WSO2esb
  • How to get current document uri in XSLT?
  • Jetty 9 HashLoginService
  • iOS: Detect app start via notification press
  • formatting the colorbar ticklabels with SymLogNorm normalization in matplotlib
  • Fetching methods from BroadcastReceiver to update UI
  • Does CUDA 5 support STL or THRUST inside the device code?
  • MySQL WHERE-condition in procedure ignored
  • Web-crawler for facebook in python
  • Proper folder structure for lots of source files
  • trying to dynamically update Highchart column chart but series undefined
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal