Changing namespace root name with java Marshaller
I generated a webservice client from a WSDL with Java wsimport tool.
But when I use the Marshaller class to generate XML file, the root namespace gets the name <Object xmlns:ns2="(...)"
.
Like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Object xmlns:ns2="(...)"
I wanted it to have a specific name like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<myName xmlns:ns2="(...)"
That's the way I used Marshaller:
Writer w = new StringWriter();
JAXBElement<ObjectType> element = new ObjectFactory().createObject(evt);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(element, w);
java xml jaxb marshalling
add a comment |
I generated a webservice client from a WSDL with Java wsimport tool.
But when I use the Marshaller class to generate XML file, the root namespace gets the name <Object xmlns:ns2="(...)"
.
Like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Object xmlns:ns2="(...)"
I wanted it to have a specific name like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<myName xmlns:ns2="(...)"
That's the way I used Marshaller:
Writer w = new StringWriter();
JAXBElement<ObjectType> element = new ObjectFactory().createObject(evt);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(element, w);
java xml jaxb marshalling
add a comment |
I generated a webservice client from a WSDL with Java wsimport tool.
But when I use the Marshaller class to generate XML file, the root namespace gets the name <Object xmlns:ns2="(...)"
.
Like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Object xmlns:ns2="(...)"
I wanted it to have a specific name like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<myName xmlns:ns2="(...)"
That's the way I used Marshaller:
Writer w = new StringWriter();
JAXBElement<ObjectType> element = new ObjectFactory().createObject(evt);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(element, w);
java xml jaxb marshalling
I generated a webservice client from a WSDL with Java wsimport tool.
But when I use the Marshaller class to generate XML file, the root namespace gets the name <Object xmlns:ns2="(...)"
.
Like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Object xmlns:ns2="(...)"
I wanted it to have a specific name like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<myName xmlns:ns2="(...)"
That's the way I used Marshaller:
Writer w = new StringWriter();
JAXBElement<ObjectType> element = new ObjectFactory().createObject(evt);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(element, w);
java xml jaxb marshalling
java xml jaxb marshalling
asked Jan 2 at 13:26
Damyhonn PaulinoDamyhonn Paulino
63
63
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Below is the code working for me. This should work for you.
JAXBContext jaxbCtx = JAXBContext.newInstance(classToBeBound.getClass());
StringWriter writer = new StringWriter();
Marshaller marshaller = jaxbCtx.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(The root of content tree to be marshalled, writer);
Thank you for your answer. But I did it. The only differece was in line "marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);" And this line didn't help. In my case "The root of content tree to be marshalled" is a JAXBElement: "JAXBElement<ObjectType> element = new ObjectFactory().createObject(evt);" And "evt" object is an ObjectType object where I set its properties to mount the final XML.
– Damyhonn Paulino
Jan 2 at 16:47
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007218%2fchanging-namespace-root-name-with-java-marshaller%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Below is the code working for me. This should work for you.
JAXBContext jaxbCtx = JAXBContext.newInstance(classToBeBound.getClass());
StringWriter writer = new StringWriter();
Marshaller marshaller = jaxbCtx.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(The root of content tree to be marshalled, writer);
Thank you for your answer. But I did it. The only differece was in line "marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);" And this line didn't help. In my case "The root of content tree to be marshalled" is a JAXBElement: "JAXBElement<ObjectType> element = new ObjectFactory().createObject(evt);" And "evt" object is an ObjectType object where I set its properties to mount the final XML.
– Damyhonn Paulino
Jan 2 at 16:47
add a comment |
Below is the code working for me. This should work for you.
JAXBContext jaxbCtx = JAXBContext.newInstance(classToBeBound.getClass());
StringWriter writer = new StringWriter();
Marshaller marshaller = jaxbCtx.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(The root of content tree to be marshalled, writer);
Thank you for your answer. But I did it. The only differece was in line "marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);" And this line didn't help. In my case "The root of content tree to be marshalled" is a JAXBElement: "JAXBElement<ObjectType> element = new ObjectFactory().createObject(evt);" And "evt" object is an ObjectType object where I set its properties to mount the final XML.
– Damyhonn Paulino
Jan 2 at 16:47
add a comment |
Below is the code working for me. This should work for you.
JAXBContext jaxbCtx = JAXBContext.newInstance(classToBeBound.getClass());
StringWriter writer = new StringWriter();
Marshaller marshaller = jaxbCtx.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(The root of content tree to be marshalled, writer);
Below is the code working for me. This should work for you.
JAXBContext jaxbCtx = JAXBContext.newInstance(classToBeBound.getClass());
StringWriter writer = new StringWriter();
Marshaller marshaller = jaxbCtx.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(The root of content tree to be marshalled, writer);
answered Jan 2 at 14:20
Ros5292Ros5292
690415
690415
Thank you for your answer. But I did it. The only differece was in line "marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);" And this line didn't help. In my case "The root of content tree to be marshalled" is a JAXBElement: "JAXBElement<ObjectType> element = new ObjectFactory().createObject(evt);" And "evt" object is an ObjectType object where I set its properties to mount the final XML.
– Damyhonn Paulino
Jan 2 at 16:47
add a comment |
Thank you for your answer. But I did it. The only differece was in line "marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);" And this line didn't help. In my case "The root of content tree to be marshalled" is a JAXBElement: "JAXBElement<ObjectType> element = new ObjectFactory().createObject(evt);" And "evt" object is an ObjectType object where I set its properties to mount the final XML.
– Damyhonn Paulino
Jan 2 at 16:47
Thank you for your answer. But I did it. The only differece was in line "marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);" And this line didn't help. In my case "The root of content tree to be marshalled" is a JAXBElement: "JAXBElement<ObjectType> element = new ObjectFactory().createObject(evt);" And "evt" object is an ObjectType object where I set its properties to mount the final XML.
– Damyhonn Paulino
Jan 2 at 16:47
Thank you for your answer. But I did it. The only differece was in line "marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);" And this line didn't help. In my case "The root of content tree to be marshalled" is a JAXBElement: "JAXBElement<ObjectType> element = new ObjectFactory().createObject(evt);" And "evt" object is an ObjectType object where I set its properties to mount the final XML.
– Damyhonn Paulino
Jan 2 at 16:47
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007218%2fchanging-namespace-root-name-with-java-marshaller%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown