Search in sources :

Example 56 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class TestGetNamespaceURI method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://www.w3.org/XML/1998/namespace", "xml");
    assertEquals("http://www.w3.org/XML/1998/namespace", ns.getNamespaceURI());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace)

Example 57 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class TestGetPrefix method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://www.w3.org/XML/1998/namespace", "xml");
    assertEquals("xml", ns.getPrefix());
    ns = factory.createOMNamespace("", null);
    assertNull(ns.getPrefix());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace)

Example 58 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class TestCloneOMElementNamespaceRepairing method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    // Create a root element on which we declare the namespaces
    OMElement root = factory.createOMElement("root", null);
    OMNamespace ns1 = root.declareNamespace("urn:ns1", "ns1");
    OMNamespace ns2 = root.declareNamespace("urn:ns2", "ns2");
    root.declareNamespace("urn:ns3", "ns3");
    // Create a child that uses these namespaces (in the element name and in the name of an attribute)
    OMElement child = factory.createOMElement("child", ns1, root);
    child.addAttribute("attr", "value", ns2);
    // Check that the child has no namespace declarations (to validate the correctness of the test)
    assertFalse(child.getAllDeclaredNamespaces().hasNext());
    // Clone the child and check that namespace declarations have been generated automatically
    OMElement clone = child.cloneOMElement();
    Set<OMNamespace> expectedNSDecls = new HashSet<>();
    expectedNSDecls.add(ns1);
    expectedNSDecls.add(ns2);
    Set<OMNamespace> actualNSDecls = new HashSet<>();
    for (Iterator<OMNamespace> it = clone.getAllDeclaredNamespaces(); it.hasNext(); ) {
        actualNSDecls.add(it.next());
    }
    assertEquals(expectedNSDecls, actualNSDecls);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) HashSet(java.util.HashSet)

Example 59 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class TestDeclareNamespace1 method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement element = metaFactory.getOMFactory().createOMElement(new QName("test"));
    OMNamespace ns = element.declareNamespace("urn:ns1", "ns1");
    assertEquals("urn:ns1", ns.getNamespaceURI());
    assertEquals("ns1", ns.getPrefix());
    Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
    assertTrue(it.hasNext());
    OMNamespace ns2 = it.next();
    assertEquals(ns, ns2);
    assertFalse(it.hasNext());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 60 with OMNamespace

use of org.apache.axiom.om.OMNamespace in project webservices-axiom by apache.

the class TestAddAttributeMultiple method runTest.

@Override
protected void runTest() throws Throwable {
    String expectedXML = "<AttributeTester xmlns:myAttr2NS=\"http://test-attributes-2.org\" " + "xmlns:myAttr1NS=\"http://test-attributes-1.org\" myAttr2NS:attrNumber=\"2\" myAttr1NS:attrNumber=\"1\" />";
    OMFactory omFactory = metaFactory.getOMFactory();
    OMNamespace attrNS1 = omFactory.createOMNamespace("http://test-attributes-1.org", "myAttr1NS");
    OMNamespace attrNS2 = omFactory.createOMNamespace("http://test-attributes-2.org", "myAttr2NS");
    OMElement omElement = omFactory.createOMElement("AttributeTester", null);
    strategy.addAttribute(omElement, "attrNumber", attrNS1, "1");
    strategy.addAttribute(omElement, "attrNumber", attrNS2, "2");
    assertAbout(xml()).that(xml(OMElement.class, omElement)).hasSameContentAs(expectedXML);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMNamespace (org.apache.axiom.om.OMNamespace)171 OMElement (org.apache.axiom.om.OMElement)108 OMFactory (org.apache.axiom.om.OMFactory)101 QName (javax.xml.namespace.QName)34 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)22 OMAttribute (org.apache.axiom.om.OMAttribute)18 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)16 StringWriter (java.io.StringWriter)15 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)13 SOAPHeader (org.apache.axiom.soap.SOAPHeader)12 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)9 XMLStreamReader (javax.xml.stream.XMLStreamReader)8 OMText (org.apache.axiom.om.OMText)7 Iterator (java.util.Iterator)6 SOAPBody (org.apache.axiom.soap.SOAPBody)6 StringReader (java.io.StringReader)5 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)5 HashSet (java.util.HashSet)4 OMDataSource (org.apache.axiom.om.OMDataSource)4 OMNode (org.apache.axiom.om.OMNode)4