Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Required tags not present when using Delphi XML Data Binding Wizard

I am using the XML Data Binding Wizard in Delphi XE2. The schema has required tags of this type:

<xs:element name="MyReport" type="MyReportType" /> <xs:complexType name="MyReportType">   <xs:all>     <xs:element name="Header" type="HeaderType" />     <xs:element name="Values" type="ValuesType" />     <xs:element name="Events" type="EventsType" />   </xs:all> </xs:complexType> 

The problem is that if I don't add any elements to e.g. the Values-group, there will be no <Values>-tag, and the XML-file will fail validation against the XSD. This probably would not be a problem if the interface was providing a method for "adding" the Values-tag.

Is there a standard way of handling this, or am I using the generated code in-correctly?

Put simply, is there any way, work-around or otherwise, using the code from the Data Binding Wizard, to produce the following XML (which is what is needed to validate using the above schema when there are no child nodes), given HeaderType, ValuesType and EventsType are of complexType:

<MyReport>   <Header />   <Values />   <Events /> </MyReport>  

(I know there are other similar issues, like the code generated by <xs:sequence> not enforcing the correct order in the final XML-file, but at least for that one, there's a work-around by simply inserting the children in the right order. I still think it would be nice if Embarcadero would provide a complete interface, which takes more of these features into account.)

like image 416
Randomeister Avatar asked Oct 01 '12 13:10

Randomeister


1 Answers

Not sure to understand but maybe what you are looking for is : use="optional"

<xs:element name="MyReport" type="MyReportType" /> <xs:complexType name="MyReportType">   <xs:all>     <xs:element name="Header" type="HeaderType" use="optional" />     <xs:element name="Values" type="ValuesType" use="optional" />     <xs:element name="Events" type="EventsType" use="optional" />   </xs:all> </xs:complexType> 

Tell me if it's okay.

like image 105
Hans Avatar answered Oct 09 '22 04:10

Hans