2

I'm using JAX-WS 2.1 (uses JAXB 2.1) under WAS7.0 app server. I've written a client code and below is the snippet from my request xml.

      <additionalCriteria>
         <ns5:keyword xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
         <ns5:maxResultsToReturn>10</ns5:maxResultsToReturn>
         <ns5:nextResultBlockKey xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
         <ns5:scope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
         <ns5:sortBy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
         <ns5:sortOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
      </additionalCriteria>

As you can see, the attribute xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" is getting added to each element. I dont want this in my request. Can any one suggest please as it is blocking my project delivery?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
MyFist
  • 413
  • 7
  • 19
  • Why do you care? For all your code knows, this XML might be cuneiform. You call the client, and the server gets called with the data. – bmargulies Dec 25 '12 at 17:13
  • 1
    I agree but people are not accepting this and they want it to be declared at envelope level. Any idea how to fix this? – MyFist Dec 25 '12 at 18:05
  • Tell 'people' that they are wrong. JAX-WS needs that namespace for xsi:nil, and can't predict if one of those is going to come up somewhere in the depths of the message. – bmargulies Dec 25 '12 at 18:46
  • ok will do that and thanks for your reply. By the way, can we manage this nsmaespace - `xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"` to be declared at envelope level instead at element/body level? – MyFist Dec 25 '12 at 18:50
  • JAX-WS owns the envelope. JAX-B owns the insides. I don't recall whether they communicate. If you add that namespace to the envelope, it may not dissuade JAX-B from adding it, again, to the body. – bmargulies Dec 25 '12 at 18:51
  • OK. Can I tell my JAX-WS client (via binding file?) to NOT to include any such elements in my request xml (when xsd says a particular element as `nil=true`) ?? I agree `minOccurs=0` will do this. – MyFist Dec 25 '12 at 19:05
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/21689/discussion-between-vamsi-and-bmargulies) – MyFist Dec 25 '12 at 19:09

1 Answers1

0

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" is necessary in case there are any nillable fields with null values down in the depths of the message. The JAX-B spec requires these to be represented with xsi:nil. JAX-WS/JAX-B cannot possibly predict if there are any of these, since it streams out the XML while walking the tree. So it always adds that namespace. It is standard, normal, and anyone who objects needs to rethink.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • OK. Can I tell my JAX-WS client (via binding file?) to NOT to include any such elements in my request xml (when xsd says a particular element as nil=true) ?? I agree minOccurs=0 will do this. – MyFist Dec 25 '12 at 19:09