0

I am working on a web service, services talk to each other with SOAPMessage (SOAP XML). SOAPMessage enters my method as a byte array

public void process(byte xmlByteArray[]){ ... ..... }

what i need is to convert this byte array to raw XML so that i can process it with JDOM.

do you know any solution for this problem?

MoienGK
  • 4,544
  • 11
  • 58
  • 92

3 Answers3

3
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(new ByteArrayInputStream(xmlByteArray));

See http://www.java2s.com/Code/Java/XML/ReadanXMLdocumentusingJDOM.htm

barq
  • 3,681
  • 4
  • 26
  • 39
1

Try this:

public static Document byteArrayToDocument( final byte[] byteArray ) throws IOException, SAXException,
        ParserConfigurationException
{
     final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     final DocumentBuilder builder = factory.newDocumentBuilder();
     return builder.parse( new ByteArrayInputStream( byteArray ) );
}
Ravi Wallau
  • 10,416
  • 2
  • 25
  • 34
0

This is how to do this in VTD-XML

import com.ximpleware.*;

public class readBytes{

    public static void main(String[] s} throws VTDException{
        VTDGen vg = new VTDGen();
        //get XML Byte array here
        vg.setDoc(xmlByteArray);
        vg.parse();
        VTDNav vn = vg.getNav();
    }
}
vtd-xml-author
  • 3,319
  • 4
  • 22
  • 30