Jaxb Unmarshar with Multiple Name Spaces
I am trying to Unmarshal a xml with multiple name spaces.
Eventually i am getting some or other exception.
Can you please guide me with best suitable solution for the below xml
I have tried using Jaxb Marshaller
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:etag=""2"">
<id>Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)</id>
<category term="SP.Data.VDI_x0020_Build_x0020_Release_x0020_ScheduleListItem"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link rel="edit" href="Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)"/>
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FirstUniqueAncestorSecurableObject"
type="application/atom+xml;type=entry" title="FirstUniqueAncestorSecurableObject"
href="Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)/FirstUniqueAncestorSecurableObject"/>
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/RoleAssignments"
type="application/atom+xml;type=feed" title="RoleAssignments"
href="Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)/RoleAssignments"/>
<title/>
<updated>2018-11-22T09:24:14Z</updated>
<author>
<name/>
</author>
<content type="application/xml">
<m:properties>
<d:FileSystemObjectType m:type="Edm.Int32">0</d:FileSystemObjectType>
<d:Id m:type="Edm.Int32">99</d:Id>
<d:Build_x0020_Release>201807</d:Build_x0020_Release>
<d:Title>1.52.201807</d:Title>
<d:Platform>LVDI3 Build (Office 2010)</d:Platform>
<d:Phase>VDI Engineering</d:Phase>
<d:Planned_x0020_Start m:type="Edm.DateTime">2018-08-03T04:00:00Z</d:Planned_x0020_Start>
<d:Planned_x0020_End m:type="Edm.DateTime">2018-08-10T04:00:00Z</d:Planned_x0020_End>
</m:properties>
</content>
</entry>
Below is the Java Code which i have tried
private Map<String, String> namespaceMap = new HashMap<>();
/**
* Create mappings.
*/
public DefaultNamespacePrefixMapper() {
namespaceMap.put("http://www.w3.org/2005/Atom", "");
namespaceMap.put("http://schemas.microsoft.com/ado/2007/08/dataservices", "d");
namespaceMap.put("http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", "m");
namespaceMap.put("http://www.georss.org/georss", "georss");
namespaceMap.put("http://www.opengis.net/gml", "gml");
}
@Override
public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
return namespaceMap.getOrDefault(namespaceUri, suggestion);
}
DefaultNamespacePrefixMapper defaultNamespacePrefixMapper = new DefaultNamespacePrefixMapper();
System.out.println("Response is::::"+response);
JAXBContext jaxbContext =JAXBContext.newInstance(Entry.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new DefaultNamespacePrefixMapper());
Object sharePointResponse = unmarshaller.unmarshal(inputStream);
java xml jaxb marshalling unmarshalling
add a comment |
I am trying to Unmarshal a xml with multiple name spaces.
Eventually i am getting some or other exception.
Can you please guide me with best suitable solution for the below xml
I have tried using Jaxb Marshaller
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:etag=""2"">
<id>Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)</id>
<category term="SP.Data.VDI_x0020_Build_x0020_Release_x0020_ScheduleListItem"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link rel="edit" href="Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)"/>
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FirstUniqueAncestorSecurableObject"
type="application/atom+xml;type=entry" title="FirstUniqueAncestorSecurableObject"
href="Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)/FirstUniqueAncestorSecurableObject"/>
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/RoleAssignments"
type="application/atom+xml;type=feed" title="RoleAssignments"
href="Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)/RoleAssignments"/>
<title/>
<updated>2018-11-22T09:24:14Z</updated>
<author>
<name/>
</author>
<content type="application/xml">
<m:properties>
<d:FileSystemObjectType m:type="Edm.Int32">0</d:FileSystemObjectType>
<d:Id m:type="Edm.Int32">99</d:Id>
<d:Build_x0020_Release>201807</d:Build_x0020_Release>
<d:Title>1.52.201807</d:Title>
<d:Platform>LVDI3 Build (Office 2010)</d:Platform>
<d:Phase>VDI Engineering</d:Phase>
<d:Planned_x0020_Start m:type="Edm.DateTime">2018-08-03T04:00:00Z</d:Planned_x0020_Start>
<d:Planned_x0020_End m:type="Edm.DateTime">2018-08-10T04:00:00Z</d:Planned_x0020_End>
</m:properties>
</content>
</entry>
Below is the Java Code which i have tried
private Map<String, String> namespaceMap = new HashMap<>();
/**
* Create mappings.
*/
public DefaultNamespacePrefixMapper() {
namespaceMap.put("http://www.w3.org/2005/Atom", "");
namespaceMap.put("http://schemas.microsoft.com/ado/2007/08/dataservices", "d");
namespaceMap.put("http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", "m");
namespaceMap.put("http://www.georss.org/georss", "georss");
namespaceMap.put("http://www.opengis.net/gml", "gml");
}
@Override
public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
return namespaceMap.getOrDefault(namespaceUri, suggestion);
}
DefaultNamespacePrefixMapper defaultNamespacePrefixMapper = new DefaultNamespacePrefixMapper();
System.out.println("Response is::::"+response);
JAXBContext jaxbContext =JAXBContext.newInstance(Entry.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new DefaultNamespacePrefixMapper());
Object sharePointResponse = unmarshaller.unmarshal(inputStream);
java xml jaxb marshalling unmarshalling
Would you mind to post exception which you're getting?
– Abhinav
Nov 22 '18 at 10:52
@Abhinav Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"entry"). Expected elements are (none) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:726) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:247) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:242)
– Sonu Agarwal
Nov 22 '18 at 12:22
Possible duplicate of javax.xml.bind.UnmarshalException: unexpected element. Expected elements are (none)
– Abhinav
Nov 22 '18 at 13:05
add a comment |
I am trying to Unmarshal a xml with multiple name spaces.
Eventually i am getting some or other exception.
Can you please guide me with best suitable solution for the below xml
I have tried using Jaxb Marshaller
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:etag=""2"">
<id>Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)</id>
<category term="SP.Data.VDI_x0020_Build_x0020_Release_x0020_ScheduleListItem"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link rel="edit" href="Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)"/>
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FirstUniqueAncestorSecurableObject"
type="application/atom+xml;type=entry" title="FirstUniqueAncestorSecurableObject"
href="Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)/FirstUniqueAncestorSecurableObject"/>
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/RoleAssignments"
type="application/atom+xml;type=feed" title="RoleAssignments"
href="Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)/RoleAssignments"/>
<title/>
<updated>2018-11-22T09:24:14Z</updated>
<author>
<name/>
</author>
<content type="application/xml">
<m:properties>
<d:FileSystemObjectType m:type="Edm.Int32">0</d:FileSystemObjectType>
<d:Id m:type="Edm.Int32">99</d:Id>
<d:Build_x0020_Release>201807</d:Build_x0020_Release>
<d:Title>1.52.201807</d:Title>
<d:Platform>LVDI3 Build (Office 2010)</d:Platform>
<d:Phase>VDI Engineering</d:Phase>
<d:Planned_x0020_Start m:type="Edm.DateTime">2018-08-03T04:00:00Z</d:Planned_x0020_Start>
<d:Planned_x0020_End m:type="Edm.DateTime">2018-08-10T04:00:00Z</d:Planned_x0020_End>
</m:properties>
</content>
</entry>
Below is the Java Code which i have tried
private Map<String, String> namespaceMap = new HashMap<>();
/**
* Create mappings.
*/
public DefaultNamespacePrefixMapper() {
namespaceMap.put("http://www.w3.org/2005/Atom", "");
namespaceMap.put("http://schemas.microsoft.com/ado/2007/08/dataservices", "d");
namespaceMap.put("http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", "m");
namespaceMap.put("http://www.georss.org/georss", "georss");
namespaceMap.put("http://www.opengis.net/gml", "gml");
}
@Override
public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
return namespaceMap.getOrDefault(namespaceUri, suggestion);
}
DefaultNamespacePrefixMapper defaultNamespacePrefixMapper = new DefaultNamespacePrefixMapper();
System.out.println("Response is::::"+response);
JAXBContext jaxbContext =JAXBContext.newInstance(Entry.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new DefaultNamespacePrefixMapper());
Object sharePointResponse = unmarshaller.unmarshal(inputStream);
java xml jaxb marshalling unmarshalling
I am trying to Unmarshal a xml with multiple name spaces.
Eventually i am getting some or other exception.
Can you please guide me with best suitable solution for the below xml
I have tried using Jaxb Marshaller
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:etag=""2"">
<id>Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)</id>
<category term="SP.Data.VDI_x0020_Build_x0020_Release_x0020_ScheduleListItem"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link rel="edit" href="Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)"/>
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FirstUniqueAncestorSecurableObject"
type="application/atom+xml;type=entry" title="FirstUniqueAncestorSecurableObject"
href="Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)/FirstUniqueAncestorSecurableObject"/>
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/RoleAssignments"
type="application/atom+xml;type=feed" title="RoleAssignments"
href="Web/Lists(guid'72cbceb5-a38b-4fdc-a37b-550794d3a78a')/Items(99)/RoleAssignments"/>
<title/>
<updated>2018-11-22T09:24:14Z</updated>
<author>
<name/>
</author>
<content type="application/xml">
<m:properties>
<d:FileSystemObjectType m:type="Edm.Int32">0</d:FileSystemObjectType>
<d:Id m:type="Edm.Int32">99</d:Id>
<d:Build_x0020_Release>201807</d:Build_x0020_Release>
<d:Title>1.52.201807</d:Title>
<d:Platform>LVDI3 Build (Office 2010)</d:Platform>
<d:Phase>VDI Engineering</d:Phase>
<d:Planned_x0020_Start m:type="Edm.DateTime">2018-08-03T04:00:00Z</d:Planned_x0020_Start>
<d:Planned_x0020_End m:type="Edm.DateTime">2018-08-10T04:00:00Z</d:Planned_x0020_End>
</m:properties>
</content>
</entry>
Below is the Java Code which i have tried
private Map<String, String> namespaceMap = new HashMap<>();
/**
* Create mappings.
*/
public DefaultNamespacePrefixMapper() {
namespaceMap.put("http://www.w3.org/2005/Atom", "");
namespaceMap.put("http://schemas.microsoft.com/ado/2007/08/dataservices", "d");
namespaceMap.put("http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", "m");
namespaceMap.put("http://www.georss.org/georss", "georss");
namespaceMap.put("http://www.opengis.net/gml", "gml");
}
@Override
public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
return namespaceMap.getOrDefault(namespaceUri, suggestion);
}
DefaultNamespacePrefixMapper defaultNamespacePrefixMapper = new DefaultNamespacePrefixMapper();
System.out.println("Response is::::"+response);
JAXBContext jaxbContext =JAXBContext.newInstance(Entry.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new DefaultNamespacePrefixMapper());
Object sharePointResponse = unmarshaller.unmarshal(inputStream);
java xml jaxb marshalling unmarshalling
java xml jaxb marshalling unmarshalling
asked Nov 22 '18 at 10:21
Sonu AgarwalSonu Agarwal
155
155
Would you mind to post exception which you're getting?
– Abhinav
Nov 22 '18 at 10:52
@Abhinav Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"entry"). Expected elements are (none) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:726) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:247) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:242)
– Sonu Agarwal
Nov 22 '18 at 12:22
Possible duplicate of javax.xml.bind.UnmarshalException: unexpected element. Expected elements are (none)
– Abhinav
Nov 22 '18 at 13:05
add a comment |
Would you mind to post exception which you're getting?
– Abhinav
Nov 22 '18 at 10:52
@Abhinav Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"entry"). Expected elements are (none) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:726) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:247) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:242)
– Sonu Agarwal
Nov 22 '18 at 12:22
Possible duplicate of javax.xml.bind.UnmarshalException: unexpected element. Expected elements are (none)
– Abhinav
Nov 22 '18 at 13:05
Would you mind to post exception which you're getting?
– Abhinav
Nov 22 '18 at 10:52
Would you mind to post exception which you're getting?
– Abhinav
Nov 22 '18 at 10:52
@Abhinav Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"entry"). Expected elements are (none) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:726) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:247) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:242)
– Sonu Agarwal
Nov 22 '18 at 12:22
@Abhinav Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"entry"). Expected elements are (none) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:726) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:247) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:242)
– Sonu Agarwal
Nov 22 '18 at 12:22
Possible duplicate of javax.xml.bind.UnmarshalException: unexpected element. Expected elements are (none)
– Abhinav
Nov 22 '18 at 13:05
Possible duplicate of javax.xml.bind.UnmarshalException: unexpected element. Expected elements are (none)
– Abhinav
Nov 22 '18 at 13:05
add a comment |
0
active
oldest
votes
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%2f53428736%2fjaxb-unmarshar-with-multiple-name-spaces%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53428736%2fjaxb-unmarshar-with-multiple-name-spaces%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
Would you mind to post exception which you're getting?
– Abhinav
Nov 22 '18 at 10:52
@Abhinav Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"entry"). Expected elements are (none) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:726) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:247) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:242)
– Sonu Agarwal
Nov 22 '18 at 12:22
Possible duplicate of javax.xml.bind.UnmarshalException: unexpected element. Expected elements are (none)
– Abhinav
Nov 22 '18 at 13:05