Search in sources :

Example 21 with Attr

use of org.w3c.dom.Attr in project robovm by robovm.

the class ElementSetAttributeNodeNS method testSetAttributeNodeNS2.

public void testSetAttributeNodeNS2() throws Throwable {
    Document doc;
    Element element;
    Element element2;
    Attr attribute;
    Attr attributeCloned;
    Attr newAttr;
    NodeList elementList;
    String attrName;
    String attrValue;
    String nullNS = null;
    doc = (Document) load("staffNS", builder);
    elementList = doc.getElementsByTagNameNS("http://www.nist.gov", "address");
    element = (Element) elementList.item(1);
    attribute = element.getAttributeNodeNS(nullNS, "street");
    attributeCloned = (Attr) attribute.cloneNode(true);
    element2 = (Element) elementList.item(2);
    newAttr = element2.setAttributeNodeNS(attributeCloned);
    attrName = newAttr.getNodeName();
    attrValue = newAttr.getNodeValue();
    assertEquals("elementsetattributenodens02_attrName", "street", attrName);
    assertEquals("elementsetattributenodens02_attrValue", "Yes", attrValue);
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 22 with Attr

use of org.w3c.dom.Attr in project robovm by robovm.

the class ElementSetAttributeNodeNS method testSetAttributeNodeNS1.

/**
     * Runs the test case.
     *
     * @throws Throwable
     *             Any uncaught exception causes test to fail
     */
public void testSetAttributeNodeNS1() throws Throwable {
    Document doc;
    Element element;
    Attr attribute1;
    Attr attribute2;
    Attr attrNode;
    String attrName;
    String attrNS;
    NamedNodeMap attributes;
    int length;
    doc = (Document) load("staff", builder);
    element = doc.createElementNS("http://www.w3.org/DOM/Test/Level2", "new:element");
    attribute1 = doc.createAttributeNS("http://www.w3.org/DOM/Test/att1", "p1:att");
    attribute2 = doc.createAttributeNS("http://www.w3.org/DOM/Test/att1", "p2:att");
    attribute2.setValue("value2");
    element.setAttributeNodeNS(attribute1);
    element.setAttributeNodeNS(attribute2);
    attrNode = element.getAttributeNodeNS("http://www.w3.org/DOM/Test/att1", "att");
    attrName = attrNode.getNodeName();
    attrNS = attrNode.getNamespaceURI();
    assertEquals("elementsetattributenodens01_attrName", "p2:att", attrName);
    assertEquals("elementsetattributenodens01_attrNS", "http://www.w3.org/DOM/Test/att1", attrNS);
    attributes = element.getAttributes();
    length = (int) attributes.getLength();
    assertEquals("length", 1, length);
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 23 with Attr

use of org.w3c.dom.Attr in project robovm by robovm.

the class ElementSetAttributeNodeNS method testSetAttributeNodeNS5.

public void testSetAttributeNodeNS5() throws Throwable {
    Document doc;
    Document docAlt;
    Element element;
    Attr attribute;
    doc = (Document) load("staffNS", builder);
    docAlt = (Document) load("staffNS", builder);
    element = doc.createElementNS("http://www.w3.org/DOM/Test", "elem1");
    attribute = docAlt.createAttributeNS("http://www.w3.org/DOM/Test", "attr");
    {
        boolean success = false;
        try {
            element.setAttributeNodeNS(attribute);
        } catch (DOMException ex) {
            success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
        }
        assertTrue("throw_WRONG_DOCUMENT_ERR", success);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 24 with Attr

use of org.w3c.dom.Attr in project robovm by robovm.

the class ElementSetAttributeNodeNS method testSetAttributeNodeNS4.

public void testSetAttributeNodeNS4() throws Throwable {
    Document doc;
    Element element1;
    Element element2;
    Attr attribute;
    doc = (Document) load("staffNS", builder);
    element1 = doc.createElementNS("http://www.w3.org/DOM/Test", "elem1");
    element2 = doc.createElementNS("http://www.w3.org/DOM/Test", "elem2");
    attribute = doc.createAttributeNS("http://www.w3.org/DOM/Test", "attr");
    element1.setAttributeNodeNS(attribute);
    {
        boolean success = false;
        try {
            element2.setAttributeNodeNS(attribute);
        } catch (DOMException ex) {
            success = (ex.code == DOMException.INUSE_ATTRIBUTE_ERR);
        }
        assertTrue("elementsetattributenodens04", success);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 25 with Attr

use of org.w3c.dom.Attr in project robovm by robovm.

the class GetAttributeNodeNS method testGetAttributeNodeNS2.

public void testGetAttributeNodeNS2() throws Throwable {
    Document doc;
    NodeList elementList;
    Element testAddr;
    Attr attribute;
    String attrName;
    doc = (Document) load("staffNS", builder);
    elementList = doc.getElementsByTagName("emp:address");
    testAddr = (Element) elementList.item(0);
    assertNotNull("empAddrNotNull", testAddr);
    attribute = testAddr.getAttributeNodeNS("http://www.nist.gov", "domestic");
    attrName = attribute.getNodeName();
    assertEquals("attrName", "emp:domestic", attrName);
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Aggregations

Attr (org.w3c.dom.Attr)385 Element (org.w3c.dom.Element)178 NamedNodeMap (org.w3c.dom.NamedNodeMap)160 Document (org.w3c.dom.Document)134 Node (org.w3c.dom.Node)126 NodeList (org.w3c.dom.NodeList)80 DOMException (org.w3c.dom.DOMException)30 ArrayList (java.util.ArrayList)25 DocumentBuilder (javax.xml.parsers.DocumentBuilder)16 HashMap (java.util.HashMap)12 Text (org.w3c.dom.Text)12 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)11 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)10 RubyString (org.jruby.RubyString)10 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)8 File (java.io.File)8 QName (javax.xml.namespace.QName)8 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)7 ParseException (java.text.ParseException)6 NokogiriHelpers.rubyStringToString (nokogiri.internals.NokogiriHelpers.rubyStringToString)6