0

I have generated Java classes from an XSD, and in my XML responses I am getting a ns2: prefix which I do not need.

For example, I am getting this response:

<ns2:location xmlns:ns2="http://www.example.com/">
  <ns2:response/>
</ns2:location>

But the response I am expecting is as follows:

<location>
  <response/>
</location>
1
  • Where are your XML responses coming from? Commented Mar 9, 2015 at 19:05

1 Answer 1

3

Your example shows not just a namespace prefix (ns2) declaration but also an actual namespace (http://www.example.com/ for the location and response elements) as not being desired.

If you have full control over the XSD, you can remove the

targetNamespace="http://www.example.com/"

attribute from the xs:schema element in the XSD. Elements of XML documents conforming to this XSD will then no longer be in any namespace, and your generated Java classes will reflect this new setting.

However, be aware that deleting (or changing) targetNamespace effectively changes the names of the components defined in the XSD. Think twice about making such a change if the XSD is defined by another party or otherwise already in use by others.

Sign up to request clarification or add additional context in comments.

7 Comments

Is it possible to do it without removing targetNamspace from XSD? i ahve full control of XSD but require targetNamespace for package creation with that name.
Somewhere your XML document will have to convey that it is in the namespace specified by targetNamespace, but read and understand Target Namespaces & Unqualified Locals to see how to get part way there while keeping targetNamespace.
Any help on how to remove namespace prefix and xmlns from xml response using jaxb or fasterxml provider
If Target Namespaces & Unqualified Locals doesn't help and you cannot remove targetNamespace then you appear to be frustrated by conflicting requirements.
yea pretty much frustrated .is it supported atleast what i am trying to do ? Can i use something like jaxbxmlprovider to get around this ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.