开发者

some problems parsing xml from webservice with JAXB

开发者 https://www.devze.com 2023-02-07 14:15 出处:网络
I am having issues with parsing the xml response got from the service at http://wiki.dbpedia.org/Look开发者_JAVA技巧up

I am having issues with parsing the xml response got from the service at http://wiki.dbpedia.org/Look开发者_JAVA技巧up

My code for the main is the one up here, toghether with annotated beans that build up the xml.

I'd like to 'debug' what's going on in the JAXBContext, so that I can see what I messed up in the annotated beans. The only thing I found it is possible is to register an EventHandler like this:

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

that prints errors like these:

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

It seems there is an unexpected element Result, but I can't manage to fix it. Can someone guide me in understanding the JAXB errors more in depth? I really can't figure out what the errors really mean (as I already have set up namespace = "http://wiki.dbpedia.org/Lookup" in the ArrayOfResult class).


You have the namespace information specified on 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 {
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号