use of com.helger.xml.microdom.MicroContainer in project ph-commons by phax.
the class MicroHelper method getAllOriginalChildrenAsContainer.
/**
* Create a micro container with all children of the passed node. If the
* passed node has no children, an empty object is returned. The resulting
* container contains the original child nodes so that they no longer belong
* to the original object. THis implies that the original object is modified!
*
* @param aParent
* The parent node to get the children from. May not be
* <code>null</code>.
* @return The micro container and never <code>null</code> but maybe empty.
*/
@Nonnull
@ReturnsMutableCopy
public static IMicroContainer getAllOriginalChildrenAsContainer(@Nonnull final IMicroNode aParent) {
final IMicroContainer ret = new MicroContainer();
aParent.forAllChildren(aChildNode -> ret.appendChild(aChildNode.detachFromParent()));
return ret;
}
use of com.helger.xml.microdom.MicroContainer in project ph-commons by phax.
the class MicroWriterTest method testGetXHTMLString.
@Test
public void testGetXHTMLString() {
final IMicroDocument aDoc = MicroReader.readMicroXML(TEST_XML);
_testGetNodeAsXHTMLString(aDoc);
_testGetNodeAsXHTMLString(aDoc.getDocumentElement());
_testGetNodeAsXHTMLString(new MicroDocument());
_testGetNodeAsXHTMLString(new MicroElement("xyz"));
_testGetNodeAsXHTMLString(new MicroContainer());
_testGetNodeAsXHTMLString(new MicroComment("useless"));
_testGetNodeAsXHTMLString(new MicroEntityReference("xyz"));
try {
_testGetNodeAsXHTMLString(null);
fail();
} catch (final NullPointerException ex) {
}
}
use of com.helger.xml.microdom.MicroContainer in project ph-commons by phax.
the class MicroWriterTest method testGetXMLString.
@Test
public void testGetXMLString() {
final IMicroDocument aDoc = MicroReader.readMicroXML(TEST_XML);
_testGetNodeAsXMLString(aDoc);
_testGetNodeAsXMLString(aDoc.getDocumentElement());
_testGetNodeAsXMLString(new MicroElement("xyz"));
_testGetNodeAsXMLString(new MicroElement("xyz").setAttribute("nsuri", "attr", "1"));
_testGetNodeAsXMLString(new MicroContainer());
_testGetNodeAsXMLString(new MicroContainer(new MicroComment("useless"), new MicroElement("xyz")));
_testGetNodeAsXMLString(new MicroComment("useless"));
_testGetNodeAsXMLString(new MicroEntityReference("xyz"));
_testGetNodeAsXMLString(new MicroCDATA("xyz"));
try {
_testGetNodeAsXMLString(null);
fail();
} catch (final NullPointerException ex) {
}
try {
MicroWriter.getNodeAsString(null, XMLWriterSettings.DEFAULT_XML_SETTINGS);
fail();
} catch (final NullPointerException ex) {
}
try {
MicroWriter.getNodeAsString(aDoc, null);
fail();
} catch (final NullPointerException ex) {
}
}
use of com.helger.xml.microdom.MicroContainer in project ph-commons by phax.
the class MicroHelper method getAllChildrenAsContainer.
/**
* Create a micro container with all children of the passed node. If the
* passed node has no children, an empty object is returned. The resulting
* container contains a clone of each child node so that the original objects
* is not modified.
*
* @param aParent
* The parent node to get the children from. May not be
* <code>null</code>.
* @return The micro container and never <code>null</code> but maybe empty.
*/
@Nonnull
@ReturnsMutableCopy
public static IMicroContainer getAllChildrenAsContainer(@Nonnull final IMicroNode aParent) {
final IMicroContainer ret = new MicroContainer();
aParent.forAllChildren(aChildNode -> ret.appendChild(aChildNode.getClone()));
return ret;
}
Aggregations