@Test public void testToXml() throws Exception { String xml = properties.toXml(); for (String fragment : sampleXmlFragments) { assertTrue(fragment, xml.contains(fragment)); } }
public Element makeRootElement(Document document) { Element root = document.createElement("properties"); List<String> keys = new ArrayList<>(keySet()); Collections.sort(keys); for (String key : keys) { WikiPageProperty childProperty = getProperty(key); toXml(childProperty, key, document, root); } return root; }
private void toXml(WikiPageProperty context, String key, Document document, Element parent) { Element element = document.createElement(key); String value = context.getValue(); if (context.hasChildren()) { if (value != null) element.setAttribute("value", value); Set<?> childKeys = context.keySet(); for (Object childKey : childKeys) { String childKeyAsString = (String) childKey; WikiPageProperty child = context.getProperty(childKeyAsString); if (child == null) { LOG.warning( "Property key \"" + childKeyAsString + "\" has null value for {" + context + "}"); } else { toXml(child, childKeyAsString, document, element); } } } else if (value != null) element.appendChild(document.createTextNode(value)); parent.appendChild(element); }