NodeHelper { public static Text addText(final TextContainer container, final String text) { if ((text == null) || text.isEmpty()) { return null; } final String append = text.trim(); if (append.isEmpty()) { return null; } final Text textNode; final Node lastChild = container.getLastChild(); if (lastChild instanceof Text) { textNode = (Text) lastChild; final String value = textNode.getNodeValue().trim(); final StringBuilder str = new StringBuilder(); str.append(value); final char first = append.charAt(0); if ((first != '.') && (first != ',') && (first != '!') && (first != '?')) { str.append(' '); } str.append(append); textNode.setNodeValue(str.toString()); } else { final Document document = container.getOwnerDocument(); final Node node = document.createTextNode(append); final XmlNodeFactory<? extends XmlNode> factory = container.getNodeFactory(); textNode = new Text(node, factory); container.appendChild(textNode); } return textNode; } private  NodeHelper(); static Text addText(final TextContainer container,
            final String text);  }
@Test public void testAddText() throws Exception { final SsmlDocument document = new SsmlDocument(); final Speak speak = document.getSpeak(); speak.addText("1"); speak.addText(" 2 3 \t "); speak.addText("\r\n4 "); speak.addText("5"); speak.addText("6"); Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<speak " + "xmlns=\"http: + "xmlns:xsi=\"http: + "version=\"1.0\" xml:lang=\"" + LanguageIdentifierConverter.toLanguageIdentifier( Locale.getDefault()) + "\" " + "xsi:schemaLocation=\"http: + "http: + "1 2 3 4 5 6</speak>", document.toString()); }