Howto parse xml-tags with prefixes using jersey and jaxb

44 Views Asked by At

I'm trying to parse XML-data which has prefixes.

I'm using Java: Jersey with Jaxb -librarys.

How to do I tell Annanotation: @XmlRootElement-to, that my xml has prefixes?

My root element is like <soapenv:Envelope>.

should my do Annotation like:

@XmlRootElement(name="soapenv:Envelope") // I'll get HTTP 400 Bad request

or

@XmlRootElement(name="/soapenv:Envelope") // I'll get HTTP 400 Bad request

or

@XmlRootElement(name="Envelope" namespace"soapenv:") // Don't remeber what I get, propably HTTP 400

or

@XmlRootElement(name="Envelope" ) //With this I'll get NullPointerException

XML-code that I need to parse:

<?xml version="1.0"?>
<soapenv:Envelope xmlns="http://someurl-1" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <customerID>CID1</customerID>
        <companyName>some company name</companyName>
    </soapenv:Body>
</soapenv:Envelope>

My java-class looks like this:

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "ns:response") // something is wrong
public class MyXMLClass {
    @XmlElement(name = "soapenv:Body" )
    public Body body;
}

I'd tried to make my easier xml-code, without prefixes and I got my code to work, but I need to work it with prefixes.

I tried to search from net also, it seems that this topic has very little info. " I also tried to put @XmlElement before, or after the @XmlRootElement, to tell what is actual element, but already javac told me it's not possible to use it that way:

@XmlElement(name = "soapenv:Envelope" )
@XmlRootElement
public class MyXMLClass {
...

So anyway: How to parse xml-tags with prefixes?

0

There are 0 best solutions below