Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Optional Element in SOAP Message using Axis  RSS feed

 
Supraja Kannaiyan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My Requirement is to have an element as optional in a Soap Message if it does not have any value.That the element should not appear in the SOAP Message.I have used minOccurs="0" for each element but still it is not working.Please suggest me a way to do this.

Thanks,
Supraja
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look here.

In Axis 1.x this is accomplished with a handler.
Custom Deployment - Introducing WSDD: More deployment - Handlers and Chains
 
Supraja Kannaiyan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply. But my Requirement is When i receive an XML Soap Message which does not have the optional elements in the message, then after the optional elements in the schema other elements are truncated.

Thanks,
Supraja
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Supraja Kannaiyan wrote:My Requirement is to have an element as optional in a Soap Message if it does not have any value.


As far as I'm aware, there is no way to do that. minOccurs=0 simply permits that a non-existent (null?) value may be represented with the absence of the element. However this does not disallow empty values, e.g. <tns:myElement /> or <tns:myElement></tns:myElement>. Also often a non-existent (null) value is represented with the xsi:nil attribute, e.g. <tns:myElement xsi:nil="true" /> which tends to be preferred by code generation tools because it is explicit in its intent.

Nil Values
But in general, the absence of an element does not have any particular meaning: It may indicate that the information is unknown, or not applicable, or the element may be absent for some other reason. Sometimes it is desirable to represent an unshipped item, unknown information, or inapplicable information explicitly with an element, rather than by an absent element. For example, it may be desirable to represent a "null" value being sent to or from a relational database with an element that is present.


So often if you wish to omit the "optional","non-existent" element you'll have to suppress it yourself (by removing it).

Also understand that <tns:myElement xsi:nil="true" /> has a different meaning than <tns:myElement />
just like String myText = null; and String myText = ""; are different.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!