Pre merge commit

This commit is contained in:
Fan-Wu Yang
2017-08-13 22:16:16 +12:00
9 changed files with 482 additions and 308 deletions
@@ -0,0 +1,36 @@
package shared.xml;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.io.StringWriter;
/**
* Created by fwy13 on 13/08/17.
*/
public class XMLUtilities {
public static String classToXML(Object o) throws JAXBException {
JAXBContext context = JAXBContext.newInstance(o.getClass());
Marshaller jaxbMarshaller = context.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(o, sw);
return sw.toString();
}
public static String xmlToClass(){
// JAXBContext jc = JAXBContext.newInstance(YourXMLClass.class);
// Unmarshaller unmarshaller = jc.createUnmarshaller();
//
// SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// URL schemaURL = // The URL to your XML Schema;
// Schema schema = sf.newSchema(schemaURL);
// unmarshaller.setSchema(schema);
//
// YourXMLClass yourXMLClass = (YourXMLClass) unmarshaller.unmarshal(xml);
}
}