use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class XMLComparator method compareChildren.
private void compareChildren(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
//ignore if the elements belong to any of the ignorable namespaces list
if (isIgnorable(elementOne) || isIgnorable(elementTwo)) {
return;
}
Iterator elementOneChildren = elementOne.getChildren();
while (elementOneChildren.hasNext()) {
OMNode omNode = (OMNode) elementOneChildren.next();
if (omNode instanceof OMElement) {
OMElement elementOneChild = (OMElement) omNode;
OMElement elementTwoChild = null;
//Do the comparison only if the element is not ignorable
if (!isIgnorable(elementOneChild)) {
elementTwoChild = elementTwo.getFirstChildWithName(elementOneChild.getQName());
//Do the comparison only if the element is not ignorable
if (!isIgnorable(elementTwoChild)) {
if (elementTwoChild == null) {
throw new XMLComparisonException(" There is no " + elementOneChild.getLocalName() + " element under " + elementTwo.getLocalName());
}
}
}
compare(elementOneChild, elementTwoChild);
}
}
}
use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class OMSerializerUtil method serializeNormal.
/**
* @deprecated This is an internal method that is no longer used.
*/
public static void serializeNormal(OMElement element, XMLStreamWriter writer, boolean cache) throws XMLStreamException {
if (cache) {
element.build();
}
serializeStartpart(element, writer);
OMNode firstChild = element.getFirstOMChild();
if (firstChild != null) {
if (cache) {
(firstChild).serialize(writer);
} else {
(firstChild).serializeAndConsume(writer);
}
}
serializeEndpart(writer);
}
use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class TestGetSAXResultWithDTD method runTest.
@Override
protected void runTest() throws Throwable {
OMElement root = metaFactory.getOMFactory().createOMElement("root", null);
SAXResult result = root.getSAXResult();
LexicalHandler lexicalHandler = result.getLexicalHandler();
ContentHandler contentHandler = result.getHandler();
contentHandler.startDocument();
lexicalHandler.startDTD("test", null, "my.dtd");
lexicalHandler.endDTD();
contentHandler.startElement("", "test", "test", new AttributesImpl());
contentHandler.endElement("", "test", "test");
contentHandler.endDocument();
OMNode child = root.getFirstOMChild();
assertTrue(child instanceof OMElement);
assertEquals("test", ((OMElement) child).getLocalName());
}
use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class TestGetChildrenRemove2 method runTest.
@Override
protected void runTest() throws Throwable {
OMElement elt = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root><child1/><child2/></root>")).getDocumentElement();
Iterator<OMNode> iter = elt.getChildren();
if (iter.hasNext()) {
iter.next();
}
iter.remove();
//this call must generate an exception
try {
iter.remove();
fail("calling remove twice without a call to next is prohibited");
} catch (IllegalStateException e) {
//ok if we come here :)
}
elt.close(false);
}
use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class TestGetChildrenRemove3 method runTest.
@Override
protected void runTest() throws Throwable {
OMElement elt = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root>a<b/><!--c--><d/>e</root>")).getDocumentElement();
Iterator<OMNode> iter = elt.getChildren();
while (iter.hasNext()) {
iter.next();
iter.remove();
}
iter = elt.getChildren();
if (iter.hasNext()) {
//we shouldn't reach here!
fail("No children should remain after removing all!");
}
elt.close(false);
}
Aggregations