Search in sources :

Example 91 with Attr

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

the class NamespaceURI method testGetNamespaceURI2.

/**
     * Runs the test case.
     *
     * @throws Throwable
     *             Any uncaught exception causes test to fail
     */
// Assumes validation.
//    public void testGetNamespaceURI1() throws Throwable {
//        Document doc;
//        NodeList elementList;
//        Element testAddr;
//        Attr addrAttr;
//        String attrNamespaceURI;
//        doc = (Document) load("staffNS", builder);
//        elementList = doc.getElementsByTagName("emp:address");
//        testAddr = (Element) elementList.item(0);
//        addrAttr = testAddr.getAttributeNodeNS("http://www.nist.gov",
//                "district");
//        attrNamespaceURI = addrAttr.getNamespaceURI();
//        assertEquals("namespaceURI", "http://www.nist.gov", attrNamespaceURI);
//    }
public void testGetNamespaceURI2() throws Throwable {
    Document doc;
    NodeList elementList;
    Element testAddr;
    Attr addrAttr;
    String attrNamespaceURI;
    doc = (Document) load("staffNS", builder);
    elementList = doc.getElementsByTagName("emp:address");
    testAddr = (Element) elementList.item(0);
    assertNotNull("empAddressNotNull", testAddr);
    addrAttr = testAddr.getAttributeNodeNS("http://www.nist.gov", "domestic");
    attrNamespaceURI = addrAttr.getNamespaceURI();
    assertEquals("namespaceURI", "http://www.nist.gov", attrNamespaceURI);
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 92 with Attr

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

the class NodeGetNamespaceURI method testGetNamespaceURI.

/**
    * Runs the test case.
    * @throws Throwable Any uncaught exception causes test to fail
    */
public void testGetNamespaceURI() throws Throwable {
    Document doc;
    Element element;
    Element elementNS;
    Attr attr;
    Attr attrNS;
    String elemNSURI;
    String elemNSURINull;
    String attrNSURI;
    String attrNSURINull;
    String nullNS = null;
    doc = (Document) load("staff", builder);
    element = doc.createElementNS(nullNS, "elem");
    elementNS = doc.createElementNS("http://www.w3.org/DOM/Test/elem", "qual:qelem");
    attr = doc.createAttributeNS(nullNS, "attr");
    attrNS = doc.createAttributeNS("http://www.w3.org/DOM/Test/attr", "qual:qattr");
    elemNSURI = elementNS.getNamespaceURI();
    elemNSURINull = element.getNamespaceURI();
    attrNSURI = attrNS.getNamespaceURI();
    attrNSURINull = attr.getNamespaceURI();
    assertEquals("nodegetnamespaceuri03_elemNSURI", "http://www.w3.org/DOM/Test/elem", elemNSURI);
    assertNull("nodegetnamespaceuri03_1", elemNSURINull);
    assertEquals("nodegetnamespaceuri03_attrNSURI", "http://www.w3.org/DOM/Test/attr", attrNSURI);
    assertNull("nodegetnamespaceuri03_2", attrNSURINull);
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 93 with Attr

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

the class NodeHasAttributes method testHasAttributes4.

public void testHasAttributes4() throws Throwable {
    Document doc;
    Document newDoc;
    DocumentType docType = null;
    DOMImplementation domImpl;
    Element element;
    Element elementTest;
    Element elementDoc;
    Attr attribute;
    NodeList elementList;
    boolean hasAttributes;
    doc = (Document) load("staffNS", builder);
    domImpl = doc.getImplementation();
    newDoc = domImpl.createDocument("http://www.w3.org/DOM/Test", "test", docType);
    element = newDoc.createElementNS("http://www.w3.org/DOM/Test", "dom:elem");
    attribute = newDoc.createAttribute("attr");
    element.setAttributeNode(attribute);
    elementDoc = newDoc.getDocumentElement();
    elementDoc.appendChild(element);
    elementList = newDoc.getElementsByTagNameNS("http://www.w3.org/DOM/Test", "elem");
    elementTest = (Element) elementList.item(0);
    hasAttributes = elementTest.hasAttributes();
    assertTrue("nodehasattributes04", hasAttributes);
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) DocumentType(org.w3c.dom.DocumentType) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 94 with Attr

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

the class SetAttributeNS method testSetAttributeNS4.

// Assumes validation.
//    public void testSetAttributeNS3() throws Throwable {
//        String namespaceURI = "www.xyz.com";
//        String qualifiedName = "emp:local1";
//        Document doc;
//        NodeList genderList;
//        Node gender;
//        NodeList genList;
//        Node gen;
//        NodeList gList;
//        Element genElement;
//        int nodeType;
//        doc = (Document) load("staffNS", builder);
//        genderList = doc.getElementsByTagName("gender");
//        gender = genderList.item(2);
//        genList = gender.getChildNodes();
//        gen = genList.item(0);
//        nodeType = (int) gen.getNodeType();
//
//        if (1 == nodeType) {
//            gen = doc.createEntityReference("ent4");
//            assertNotNull("createdEntRefNotNull", gen);
//        }
//        gList = gen.getChildNodes();
//        genElement = (Element) gList.item(0);
//        assertNotNull("notnull", genElement);
//
//        {
//            boolean success = false;
//            try {
//                genElement.setAttributeNS(namespaceURI, qualifiedName,
//                        "newValue");
//            } catch (DOMException ex) {
//                success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
//            }
//            assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR", success);
//        }
//    }
public void testSetAttributeNS4() throws Throwable {
    Document doc;
    NodeList elementList;
    Node testAddr;
    Attr addrAttr;
    String resultAttr;
    String resultNamespaceURI;
    String resultLocalName;
    String resultPrefix;
    doc = (Document) load("staffNS", builder);
    elementList = doc.getElementsByTagName("emp:address");
    testAddr = elementList.item(0);
    assertNotNull("empAddrNotNull", testAddr);
    ((Element) /* Node */
    testAddr).setAttributeNS("http://www.nist.gov", "newprefix:zone", "newValue");
    addrAttr = ((Element) /* Node */
    testAddr).getAttributeNodeNS("http://www.nist.gov", "zone");
    resultAttr = ((Element) /* Node */
    testAddr).getAttributeNS("http://www.nist.gov", "zone");
    assertEquals("attrValue", "newValue", resultAttr);
    resultNamespaceURI = addrAttr.getNamespaceURI();
    assertEquals("nsuri", "http://www.nist.gov", resultNamespaceURI);
    resultLocalName = addrAttr.getLocalName();
    assertEquals("lname", "zone", resultLocalName);
    resultPrefix = addrAttr.getPrefix();
    assertEquals("prefix", "newprefix", resultPrefix);
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 95 with Attr

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

the class SetAttributeNS method testSetAttributeNS9.

public void testSetAttributeNS9() throws Throwable {
    String localName = "newAttr";
    String namespaceURI = "http://www.newattr.com";
    String qualifiedName = "emp:newAttr";
    Document doc;
    NodeList elementList;
    Node testAddr;
    Attr addrAttr;
    String resultAttr;
    String resultNamespaceURI;
    String resultLocalName;
    String resultPrefix;
    doc = (Document) load("staffNS", builder);
    elementList = doc.getElementsByTagName("emp:address");
    testAddr = elementList.item(0);
    assertNotNull("empAddrNotNull", testAddr);
    ((Element) /* Node */
    testAddr).setAttributeNS(namespaceURI, qualifiedName, "newValue");
    addrAttr = ((Element) /* Node */
    testAddr).getAttributeNodeNS(namespaceURI, localName);
    resultAttr = ((Element) /* Node */
    testAddr).getAttributeNS(namespaceURI, localName);
    assertEquals("attrValue", "newValue", resultAttr);
    resultNamespaceURI = addrAttr.getNamespaceURI();
    assertEquals("nsuri", "http://www.newattr.com", resultNamespaceURI);
    resultLocalName = addrAttr.getLocalName();
    assertEquals("lname", "newAttr", resultLocalName);
    resultPrefix = addrAttr.getPrefix();
    assertEquals("prefix", "emp", resultPrefix);
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Aggregations

Attr (org.w3c.dom.Attr)461 Element (org.w3c.dom.Element)215 NamedNodeMap (org.w3c.dom.NamedNodeMap)194 Node (org.w3c.dom.Node)153 Document (org.w3c.dom.Document)147 NodeList (org.w3c.dom.NodeList)89 ArrayList (java.util.ArrayList)33 DOMException (org.w3c.dom.DOMException)32 QName (javax.xml.namespace.QName)22 HashMap (java.util.HashMap)18 DocumentBuilder (javax.xml.parsers.DocumentBuilder)17 Text (org.w3c.dom.Text)14 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)13 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)10 RubyString (org.jruby.RubyString)10 IOException (java.io.IOException)9 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)8 File (java.io.File)8 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)8 ParseException (java.text.ParseException)6