use of org.apache.axiom.om.OMAttribute in project webservices-axiom by apache.
the class TestAddAttributeReuseExistingPrefix method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement parent = factory.createOMElement("parent", null);
OMElement element = factory.createOMElement("element", null, parent);
parent.declareNamespace("urn:test", "p");
OMAttribute attr = element.addAttribute("attr", "test", factory.createOMNamespace("urn:test", null));
assertThat(attr).hasPrefix("p");
assertThat(element).hasNoNamespaceDeclarations();
}
use of org.apache.axiom.om.OMAttribute in project webservices-axiom by apache.
the class TestGetAttributeWithXmlPrefix1 method runTest.
@Override
protected void runTest() throws Throwable {
OMElement elem = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<wsp:Policy xml:base=\"uri:thisBase\" " + "xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">" + "</wsp:Policy>");
OMAttribute attr = elem.getAttribute(new QName(XMLConstants.XML_NS_URI, "base"));
assertEquals("Attribute namespace mismatch", XMLConstants.XML_NS_URI, attr.getNamespace().getNamespaceURI());
}
use of org.apache.axiom.om.OMAttribute in project webservices-axiom by apache.
the class TestGetAllAttributes2 method runTest.
@Override
protected void runTest() throws Throwable {
OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(), "<e xmlns:p='urn:test' p:attr='test'/>");
Iterator<OMAttribute> it = element.getAllAttributes();
assertTrue(it.hasNext());
OMAttribute attr = it.next();
assertEquals("urn:test", attr.getNamespace().getNamespaceURI());
assertEquals("attr", attr.getLocalName());
assertFalse(it.hasNext());
}
use of org.apache.axiom.om.OMAttribute in project webservices-axiom by apache.
the class TestAddAttribute method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMSourcedElement element = factory.createOMElement(new PullOMDataSource("<root attr='orgvalue'><child/></root>"), "root", null);
// Add an attribute before expansion
OMAttribute attr = strategy.addAttribute(element, "attr", null, "newvalue");
// Force expansion; this should not overwrite the attribute we just added
assertThat(element.getFirstOMChild()).isNotNull();
OMAttribute attr2 = element.getAttribute(new QName("attr"));
assertThat(attr2).isSameAs(attr);
assertThat(attr2.getAttributeValue()).isEqualTo("newvalue");
Iterator<OMAttribute> it = element.getAllAttributes();
assertThat(it.hasNext()).isTrue();
assertThat(it.next()).isSameAs(attr);
assertThat(it.hasNext()).isFalse();
}
use of org.apache.axiom.om.OMAttribute in project webservices-axiom by apache.
the class SAXResultContentHandler method processAttribute.
@Override
public void processAttribute(String namespaceURI, String localName, String prefix, String value, String type, boolean specified) {
OMElement element = (OMElement) target;
OMNamespace ns;
if (namespaceURI.length() > 0) {
ns = element.findNamespace(namespaceURI, prefix);
if (ns == null) {
throw new OMException("Unbound namespace " + namespaceURI);
}
} else {
ns = null;
}
OMAttribute attr = element.addAttribute(localName, value, ns);
attr.setAttributeType(type);
}
Aggregations