Reputation: 4654
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?
Upvotes: 0
Views: 8893
Reputation: 3377
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();
}
}
Upvotes: 0
Reputation: 3711
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(new ByteArrayInputStream(xmlByteArray));
See http://www.java2s.com/Code/Java/XML/ReadanXMLdocumentusingJDOM.htm
Upvotes: 3
Reputation: 10493
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 ) );
}
Upvotes: 1