Jaxb Unmarshar with Multiple Name Spaces












0















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="&quot;2&quot;">
<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);









share|improve this question























  • 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
















0















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="&quot;2&quot;">
<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);









share|improve this question























  • 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














0












0








0








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="&quot;2&quot;">
<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);









share|improve this question














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="&quot;2&quot;">
<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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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



















  • 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












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
});


}
});














draft saved

draft discarded


















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
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin