Search in sources :

Example 16 with OMAttribute

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();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 17 with OMAttribute

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());
}
Also used : QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 18 with OMAttribute

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());
}
Also used : OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 19 with OMAttribute

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();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) QName(javax.xml.namespace.QName) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 20 with OMAttribute

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);
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) OMException(org.apache.axiom.om.OMException) OMAttribute(org.apache.axiom.om.OMAttribute)

Aggregations

OMAttribute (org.apache.axiom.om.OMAttribute)55 OMFactory (org.apache.axiom.om.OMFactory)31 OMElement (org.apache.axiom.om.OMElement)26 OMNamespace (org.apache.axiom.om.OMNamespace)18 QName (javax.xml.namespace.QName)16 OMNode (org.apache.axiom.om.OMNode)4 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)4 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)4 Attr (org.w3c.dom.Attr)4 StringReader (java.io.StringReader)3 OMException (org.apache.axiom.om.OMException)3 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)3 SOAPFaultText (org.apache.axiom.soap.SOAPFaultText)3 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)3 Element (org.w3c.dom.Element)3 OMDocument (org.apache.axiom.om.OMDocument)2 OMText (org.apache.axiom.om.OMText)2 SOAPBody (org.apache.axiom.soap.SOAPBody)2 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)2 SOAPFault (org.apache.axiom.soap.SOAPFault)2