tags:

views:

50

answers:

3

I've a JMS messaging app thats reading and writing to MQ queues. The message data is string form and in xml format (minus the normal header markers like the xml version etc). I'm looking at the best ways to read in, write out and validate against an xsd schema however the examples I'm coming across all talk about working with files.

Is there any way (tutorials out there) to take an xml string; read it in and validate it and also do the same for an xml string I create validate and write out without writing to disk?

Would appreciate any pointers.

A: 

Check out the javax.xml.validation APIs in Java SE, in particular the Validator class which is used to validate XML content against an XML schema:

Blaise Doughan
A: 

Use a StringReader on the strings, pass the reader to the JAXB methods to read the contents.

Tassos Bassoukos
A: 

thanks folks I managed to sort this one out with the following.

Marshall:

JAXBContext jaxbContext = JAXUtility.getContext(packageLocation); StringWriter sw = new StringWriter(); Marshaller m = jaxbContext.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); if (o instanceof UnadvisedDeal) { m.marshal((UnadvisedDeal) o,sw);

UnMarshall:

JAXBContext jaxbContext = JAXUtility.getContext(packageLocation); Unmarshaller um = jaxbContext.createUnmarshaller(); ud = (UnadvisedDeal) um.unmarshal(new StringReader(sw.toString()));

thanks for the help though

sapatos