mercredi 30 mars 2011

 

Unmarshaller une strings qui contient de l'XML

comment unmarshaller une String qui contient de l'XML

1. En utilsant ByteArrayInputStream

    public ObjectApartirDeStringXML (String stringXML){
   .......
    JAXBContext jContext=......
    Unmarshaller u =  jContext.createUnmarshaller();
    ByteArrayInputStream input = new ByteArrayInputStream (stringXML.getBytes());
    Object jaxbObject = unmarshaller.unmarshal( input);
   .........

2  En utilsant StreamSource

    JAXBContext jContext=......
    Unmarshaller u =  jContext.createUnmarshaller();
    StringBuffer xmlSb = new StringBuffer( “<?xml version=”1.0″?>…” );
    Object o = u.unmarshal( new StreamSource( new StringReader( xmlSb.toString() ) ) );
    ....

Libellés :


Commentaires:

Enregistrer un commentaire

Abonnement Publier les commentaires [Atom]





<< Accueil

This page is powered by Blogger. Isn't yours?

Abonnement Articles [Atom]