use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class OMXMLParserWrapperImpl method getDocumentElement.
@Override
public final OMElement getDocumentElement(boolean discardDocument) {
try {
OMDocument document = getDocument();
OMElement element = document.getOMDocumentElement();
if (discardDocument) {
element.detach();
((AxiomDocument) document).coreDiscard(false);
}
return element;
} catch (CoreModelException ex) {
throw AxiomExceptionTranslator.translate(ex);
}
}
use of org.apache.axiom.om.OMElement 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.OMElement in project webservices-axiom by apache.
the class OMChildrenWithSpecificAttributeIteratorTest method testChildrenRetrievalWithDetaching.
public void testChildrenRetrievalWithDetaching() {
OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace testNamespace = factory.createOMNamespace("http://test.ws.org", "test");
OMElement documentElement = getSampleDocumentElement(testNamespace);
Iterator childrenIter = new OMChildrenWithSpecificAttributeIterator(documentElement.getFirstOMChild(), new QName(testNamespace.getNamespaceURI(), "myAttr", testNamespace.getPrefix()), "Axis2", true);
int childCount = getChidrenCount(childrenIter);
assertEquals("Iterator must return 5 children with the given attribute", childCount, 5);
Iterator children = documentElement.getChildren();
childCount = getChidrenCount(children);
assertEquals("Iterator must return only one child, having detached the other children", childCount, 1);
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetXMLStreamReaderWithPreserveNamespaceContext method runTest.
@Override
protected void runTest() throws Throwable {
InputStream in = TestGetXMLStreamReaderWithPreserveNamespaceContext.class.getResourceAsStream("AXIOM-114.xml");
OMElement root = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), in).getDocumentElement();
root.declareNamespace("http://example.org", "p");
OMXMLStreamReaderConfiguration configuration = new OMXMLStreamReaderConfiguration();
configuration.setPreserveNamespaceContext(preserveNamespaceContext);
XMLStreamReader reader = root.getFirstElement().getFirstElement().getXMLStreamReader(cache, configuration);
assertThat(reader.next()).isEqualTo(XMLStreamReader.START_ELEMENT);
Set<String> prefixes = new HashSet<>();
for (int i = 0; i < reader.getNamespaceCount(); i++) {
prefixes.add(reader.getNamespacePrefix(i));
}
if (preserveNamespaceContext) {
assertThat(prefixes).containsExactly("soapenv", "xsd", "xsi", "ns", "p");
} else {
assertThat(prefixes).containsExactly("ns");
}
// Make sure that we start pulling events directly from the underlying parser.
reader.nextTag();
// The following assertions are true irrespective of the value of preserveNamespaceContext.
assertThat(reader.getNamespaceURI("xsd")).isEqualTo("http://www.w3.org/2001/XMLSchema");
// Namespace declarations added programmatically on an ancestor should also be visible.
assertThat(reader.getNamespaceURI("p")).isEqualTo("http://example.org");
NamespaceContext nc = reader.getNamespaceContext();
assertThat(nc.getPrefix("http://www.w3.org/2001/XMLSchema")).isEqualTo("xsd");
assertThat(nc.getPrefix("http://example.org")).isEqualTo("p");
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetXMLStreamReaderWithoutCachingPartiallyBuilt method runTest.
@Override
protected void runTest() throws Throwable {
// Note: the problem described in AXIOM-393 specifically occurred with descendants
// having the same name as the root element
OMElement root = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<element><element><element/><element/></element></element>")).getDocumentElement();
// Partially build the tree
root.getFirstElement().getFirstElement();
XMLStreamReader reader = root.getXMLStreamReaderWithoutCaching();
int depth = 0;
while (reader.hasNext()) {
int event = reader.next();
if (event == XMLStreamReader.START_ELEMENT) {
depth++;
} else if (event == XMLStreamReader.END_ELEMENT) {
depth--;
}
}
assertEquals(0, depth);
}
Aggregations