Search in sources :

Example 1 with MicroContainer

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;
}
Also used : MicroContainer(com.helger.xml.microdom.MicroContainer) IMicroContainer(com.helger.xml.microdom.IMicroContainer) IMicroContainer(com.helger.xml.microdom.IMicroContainer) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Example 2 with MicroContainer

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) {
    }
}
Also used : IMicroDocument(com.helger.xml.microdom.IMicroDocument) MicroDocument(com.helger.xml.microdom.MicroDocument) IMicroElement(com.helger.xml.microdom.IMicroElement) MicroElement(com.helger.xml.microdom.MicroElement) MicroContainer(com.helger.xml.microdom.MicroContainer) MicroComment(com.helger.xml.microdom.MicroComment) MicroEntityReference(com.helger.xml.microdom.MicroEntityReference) IMicroDocument(com.helger.xml.microdom.IMicroDocument) Test(org.junit.Test)

Example 3 with MicroContainer

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) {
    }
}
Also used : IMicroElement(com.helger.xml.microdom.IMicroElement) MicroElement(com.helger.xml.microdom.MicroElement) MicroContainer(com.helger.xml.microdom.MicroContainer) MicroCDATA(com.helger.xml.microdom.MicroCDATA) MicroComment(com.helger.xml.microdom.MicroComment) MicroEntityReference(com.helger.xml.microdom.MicroEntityReference) IMicroDocument(com.helger.xml.microdom.IMicroDocument) Test(org.junit.Test)

Example 4 with MicroContainer

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;
}
Also used : MicroContainer(com.helger.xml.microdom.MicroContainer) IMicroContainer(com.helger.xml.microdom.IMicroContainer) IMicroContainer(com.helger.xml.microdom.IMicroContainer) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Aggregations

MicroContainer (com.helger.xml.microdom.MicroContainer)4 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)2 IMicroContainer (com.helger.xml.microdom.IMicroContainer)2 IMicroDocument (com.helger.xml.microdom.IMicroDocument)2 IMicroElement (com.helger.xml.microdom.IMicroElement)2 MicroComment (com.helger.xml.microdom.MicroComment)2 MicroElement (com.helger.xml.microdom.MicroElement)2 MicroEntityReference (com.helger.xml.microdom.MicroEntityReference)2 Nonnull (javax.annotation.Nonnull)2 Test (org.junit.Test)2 MicroCDATA (com.helger.xml.microdom.MicroCDATA)1 MicroDocument (com.helger.xml.microdom.MicroDocument)1