2011-04-06 15 views
6

Tengo un cliente que estoy creando para acceder a un servicio web. Estoy usando algunas clases generadas por JAXB (Netbeans 6.9) para desmantelar mis datos xml.JAXB unmarshaling Ignorando las etiquetas SOAP Sobre/Encabezado

Recibo errores inesperados de elementos cuando trato de eliminar la respuesta InputStream de este servicio web, también obtengo el mismo error de elemento inesperado si guardo la respuesta a un archivo.

javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.w3.org/2003/05/soap-envelope", local:"Envelope"). Expected elements are <{http://www.cmicdataservices.com/}Authentication>,.... 

Con los datos guardados en un archivo que pueda entrar y eliminar las etiquetas de jabón (sobre, cuerpo, headr) y ejecute el unmarshaling sin ningún problema.

Realmente no he encontrado una manera de hacer que el despegue ignore estas etiquetas. ¿Alguien sabe qué se puede hacer para ignorar esas etiquetas?

Este es el método principal y la clase devuelta por la transmisión.

public static void main(String[] args) { 
     JAXBContext jaxbContext = null; 
     try { 
      CMICData cmic = new CMICData(); 
      jaxbContext = JAXBContext.newInstance("cmic.ajrs.com"); 
      Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 


      GetCurrentDataVer1Response response = (GetCurrentDataVer1Response) 
        unmarshaller.unmarshal(cmic.getCMICIs("GetCurrentDataVer1")); 
      DatacenterDataVer1 dataSet = response.getGetCurrentDataVer1Result(); 

      List products = dataSet.getAProductBase().getProductBase(); 
      // print some primary keys to show data being processed. 
      for(Iterator<ProductBase> iter = products.iterator(); iter.hasNext();) { 
       ProductBase pb = iter.next(); 
       System.out.println(pb.getPkID()); 
      } 

     } catch (JAXBException ex) { 
      Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); 
     } 
     catch (IOException ex) { 
      Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); 
     } 


    } 

La clase generado por Netbeans.

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "", propOrder = { 
    "getCurrentDataVer1Result" 
}) 
@XmlRootElement(name = "GetCurrentDataVer1Response", namespace = "http://www.cmicdataservices.com/") 
public class GetCurrentDataVer1Response { 

    @XmlElement(name = "GetCurrentDataVer1Result") 
    protected DatacenterDataVer1 getCurrentDataVer1Result; 

    /** 
    * Gets the value of the getCurrentDataVer1Result property. 
    * 
    * @return 
    *  possible object is 
    *  {@link DatacenterDataVer1 } 
    *  
    */ 
    public DatacenterDataVer1 getGetCurrentDataVer1Result() { 
     return getCurrentDataVer1Result; 
    } 

    /** 
    * Sets the value of the getCurrentDataVer1Result property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link DatacenterDataVer1 } 
    *  
    */ 
    public void setGetCurrentDataVer1Result(DatacenterDataVer1 value) { 
     this.getCurrentDataVer1Result = value; 
    } 

} 
+0

Vea aquí http://stackoverflow.com/questions/5044042/jaxb-ignore-element – laz

Respuesta

5

Hay un par de opciones diferentes:

Opción # 1

Si recibe la entrada XML como InputStream se podría analizar con StAX y obtener una XMLStreamReader. Luego puede avanzar el XMLStreamReader al elemento raíz local que desea desasignar y hacer que JAXB lo desmarque.

Opción # 2

usted podría utilizar la biblioteca javax.xml.xpath para seleccionar el elemento raíz local que desea deserializar con JAXB. Para un ejemplo javax.xml.xpath ver:

Cuestiones relacionadas