I'm working on soap webservices. i want to know how to display response xml with empty elements when the data is null.
Eg:
My XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="TrackInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" />
<xs:element name="Length" type="xs:string" />
<xs:element name="AverageSpeed" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Sample XML document:
<TrackInfo>
<Name>Barcelona</Name>
<Length>4591</Length>
<AverageSpeed>20</AverageSpeed>
</TrackInfo>
Java Code to set values
TrackInfo trackinfo= new TrackInfo();
trackinfo.setName("Barcelona");
trackinfo.setLength("4591");
trackinfo.setAverageSpeed("20");
There are cases where i may not have data to set and in that case i want to display xml with empty elements. Otherwise i need to handle null cases for huge code.
TrackInfo trackinfo= new TrackInfo();
trackinfo.setName(null);
trackinfo.setLength(null);
trackinfo.setAverageSpeed(null);
<TrackInfo>
<Name></Name>
<Length></Length>
<AverageSpeed></AverageSpeed>
</TrackInfo>
if i try with nillable=true i get response as
<TrackInfo>
<Name xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<Length xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance"/>
<AverageSpeed xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</TrackInfo>
Please advise how to proceed for any other possibilities
Thanks.
i want to know how to display response xml with empty elements when the data is null
... it appears that usingnillable="true"
is achieving this. Then what else is the problem?