Some problems parsing xml from webservice with JAXB

I'm having trouble parsing the XML response received from the service at http://wiki.dbpedia.org/Lookup

My code for the main one is here , toghether with annotated beans, which creates xml.

I would like to “debug” what happens in JAXBContextso that I can see what I messed up in annotated beans. The only thing I found is to register EventHandleras follows:

unmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());   

which prints such errors:

uri http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryString=galway&MaxHits=5
DefaultValidationEventHandler: [ERROR]: unexpected element (uri:"http://lookup.dbpedia.org/", local:"Result"). Expected elements are <{}Result> 
     Location: line 3

There seems to be an unexpected Result element, but I can't fix it. Can someone help me better understand JAXB errors? I really can't understand what the errors really mean (as I already installed namespace = "http://wiki.dbpedia.org/Lookup"in the class ArrayOfResult).

+3
source share
1 answer

You have namespace information specified in ArrayOfResult, but not on Result:

package it.cybion.dbpedia.textsearch.rest.response;

import java.net.URI;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "Result", namespace="http://lookup.dbpedia.org/")
@XmlAccessorType(XmlAccessType.FIELD)
public class Result {
}
+2
source

Source: https://habr.com/ru/post/1789064/


All Articles