Java Utililty Methods XML Transform Usage

List of utility methods to do XML Transform Usage

Description

The list of methods to do XML Transform Usage are organized into topic(s).

Method

StringencodeBase64(Element elm)
encode Base
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
TransformerFactory transFac = TransformerFactory.newInstance();
Transformer trans = transFac.newTransformer();
trans.transform(new DOMSource(elm), new StreamResult(ostream));
return (new String(Base64.encodeBase64(ostream.toByteArray(), true)));
StringgetCalendarAsXsdDateTime(Calendar c)
Transforms a given Java Calendar object to a xsd:DateTime String.
return DatatypeConverter.printDateTime(c);
StringgetContentText(Element element)
get Content Text
StringBuffer buffer = new StringBuffer();
NodeList nodeList = element.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
    Node node = nodeList.item(i);
    if (node instanceof CharacterData) {
        CharacterData characterData = (CharacterData) node;
        buffer.append(characterData.getData());
return buffer.toString();
DategetDate(final XMLGregorianCalendar xmlGregorianCalendar)
Takes an XMLGregorianCalendar and converts it to an Date .
Date date = null;
if (xmlGregorianCalendar != null) {
    final GregorianCalendar gregorianCalendar = xmlGregorianCalendar.toGregorianCalendar();
    date = gregorianCalendar.getTime();
return date;
voidgetEmptyXmlFile(File xmlFile)
creates a new xmlfile with a "reports" son for the reports usage
Element main;
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = db.newDocument();
main = doc.createElement("reports");
doc.appendChild(main);
saveDocumentToFile(doc, xmlFile);
ObjectgetImplementationObject()
get Implementation Object
Service service = Service.create(new QName("dummyService"));
Object obj = service.getHandlerResolver();
if (obj == null) {
    service.addPort(new QName("dummyPort"), SOAPBinding.SOAP11HTTP_BINDING, "http://dummy-address");
    obj = service.createDispatch(new QName("dummyPort"), Source.class, Mode.PAYLOAD);
return obj;
ReadergetNormalizedReader(Reader reader)
get Normalized Reader
return reader;
SAXSourcegetSaxSource(File newFile, SAXParserFactory spf)
get Sax Source
XMLReader xmlReader = spf.newSAXParser().getXMLReader();
return new SAXSource(xmlReader, new InputSource(new FileInputStream(newFile)));
SchemagetSchema(InputStream... inputs)
get Schema
StreamSource[] streamSource = new StreamSource[inputs.length];
for (int i = 0; i < inputs.length; i++) {
    streamSource[i] = new StreamSource(inputs[i]);
SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(streamSource);
return schema;
SourcegetSourceFromEndpointReference(EndpointReference epr)
get Source From Endpoint Reference
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
StreamResult result = new StreamResult(outputStream);
epr.writeTo(result);
return new StreamSource(new ByteArrayInputStream(outputStream.toByteArray()));