All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bytekast.sweettalk.util.NamespaceUtil.groovy Maven / Gradle / Ivy

The newest version!
package com.bytekast.sweettalk.util

import groovy.transform.CompileStatic
import groovy.xml.XmlUtil

import javax.xml.transform.TransformerFactory
import javax.xml.transform.stream.StreamResult
import javax.xml.transform.stream.StreamSource

@Singleton
@CompileStatic
class NamespaceUtil {

  private applyXslt(String xslt, String xml) {
    def transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(new StringReader(xslt)))
    def writer = new StringWriter()
    transformer.transform(new StreamSource(new StringReader(xml.trim())), new StreamResult(writer))
    XmlUtil.serialize(writer.toString())
  }

  String removeXmlNamespaces(String xml) {
    applyXslt(this.class.getResource('/remove_namespaces.xslt').text?.trim(), xml)
  }

  String normalizeXmlNamespaces(String xml) {
    applyXslt(this.class.getResource('/normalize_namespaces.xslt').text?.trim(), xml)
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy