Java Utililty Methods XML String Transform

List of utility methods to do XML String Transform

Description

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

Method

Stringencode(final String value)
XML-encode a String
final StringBuffer sb = new StringBuffer();
for (int i = 0; i < value.length(); ++i) {
    final char c = value.charAt(i);
    switch (c) {
    case '&':
        sb.append("&amp;");
        break;
    case '<':
...
StringencodeStringIntoMemento(String str)
Returns a XML memento, that encodes a single String parameter
List<String> list = new ArrayList<>();
list.add(str);
return encodeListIntoMemento(list);
StringescapeBackslashes(String value)
Escapes backslashes ('\') with additional backslashes in a given String, returning a new, escaped String.
StringBuilder buf = new StringBuilder(value);
for (int looper = 0; looper < buf.length(); looper++) {
    char curr = buf.charAt(looper);
    char next = 0;
    if (looper + 1 < buf.length())
        next = buf.charAt(looper + 1);
    if (curr == '\\') {
        if (next != '\\') { 
...
LinkedHashMapextractAndNormalizeEmbedPictures(String xmlFile, String odtFile, String parentDir, String imgBaseDir)
Extract and normalize picture names, i.e.
logger.fine("entering");
ZipFile zip;
File imgDir;
ArrayList<String> pics;
DocumentBuilderFactory docFactory;
DocumentBuilder docBuilder;
Document contentDoc;
LinkedHashMap<String, String> oldAndNewImgNames = new LinkedHashMap<String, String>();
...
StringextractElement(String xml, String tagName)
extract Element
InputSource xmlSource = new InputSource(new StringReader(xml));
return createXmlString(extractElement(createXmlDocument(xmlSource), tagName));
voidextractText(Node n, StringBuffer buf)
extract Text
if (n.getNodeType() == Node.TEXT_NODE) {
    buf.append(n.getNodeValue());
for (n = n.getFirstChild(); n != null; n = n.getNextSibling()) {
    extractText(n, buf);
StringfileToXMLString(String filename)
file To XML String
return sourceToXMLString(new StreamSource(new File(filename)));
StringgetAsXMLString(final Node node)
Transforms an org.w3c.dom.Document into a String
final Transformer tf = TransformerFactory.newInstance().newTransformer();
final StringWriter stringWriter = new StringWriter();
tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
tf.transform(new DOMSource(node), new StreamResult(stringWriter));
return stringWriter.toString();
StringgetBeanDefinition(String beanId, File file)
get Bean Definition
String beanDefinition = null;
InputStream stream = null;
try {
    stream = new FileInputStream(file);
    Element rootElement = loadRootElement(stream);
    beanDefinition = loadBeanDef(rootElement, beanId);
} catch (Exception e) {
    throw e;
...
StringgetConfigurationAsXML(Map properties)
Get a set of properties as an XML Configuration
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
Element entity = doc.createElement("entity");
doc.appendChild(entity);
for (Map.Entry<String, Object> element : properties.entrySet()) {
    String key = element.getKey();
    Object value = element.getValue();
...