Search in sources :

Example 51 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project nokogiri by sparklemotion.

the class XmlDocument method removeNamespceRecursively.

private void removeNamespceRecursively(ThreadContext context, XmlNode xmlNode) {
    Node node = xmlNode.node;
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        node.setPrefix(null);
        NokogiriHelpers.renameNode(node, null, node.getLocalName());
        NamedNodeMap attrs = node.getAttributes();
        for (int i = 0; i < attrs.getLength(); i++) {
            Attr attr = (Attr) attrs.item(i);
            if (isNamespace(attr.getNodeName())) {
                ((org.w3c.dom.Element) node).removeAttributeNode(attr);
            } else {
                attr.setPrefix(null);
                NokogiriHelpers.renameNode(attr, null, attr.getLocalName());
            }
        }
    }
    XmlNodeSet nodeSet = (XmlNodeSet) xmlNode.children(context);
    for (long i = 0; i < nodeSet.length(); i++) {
        XmlNode childNode = (XmlNode) nodeSet.slice(context, RubyFixnum.newFixnum(context.getRuntime(), i));
        removeNamespceRecursively(context, childNode);
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node) Attr(org.w3c.dom.Attr)

Example 52 with NamedNodeMap

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

the class NamedNodeMapSetNamedItemNS method testSetNamedItemNS6.

// Assumes validation.
//    public void testSetNamedItemNS5() throws Throwable {
//        Document doc;
//        DocumentType docType;
//        NamedNodeMap entities;
//        NamedNodeMap notations;
//        Entity entity;
//        Notation notation;
//
//        doc = (Document) load("staffNS", builder);
//        docType = doc.getDoctype();
//        entities = docType.getEntities();
//        assertNotNull("entitiesNotNull", entities);
//        notations = docType.getNotations();
//        assertNotNull("notationsNotNull", notations);
//        entity = (Entity) entities.getNamedItem("ent1");
//        notation = (Notation) notations.getNamedItem("notation1");
//
//        {
//            boolean success = false;
//            try {
//                entities.setNamedItemNS(entity);
//            } catch (DOMException ex) {
//                success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
//            }
//            assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR_entities", success);
//        }
//
//        {
//            boolean success = false;
//            try {
//                notations.setNamedItemNS(notation);
//            } catch (DOMException ex) {
//                success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
//            }
//            assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR_notations", success);
//        }
//    }
public void testSetNamedItemNS6() throws Throwable {
    Document doc;
    NamedNodeMap attributes;
    NodeList elementList;
    Element element;
    Attr attr;
    doc = (Document) load("staffNS", builder);
    elementList = doc.getElementsByTagNameNS("*", "address");
    element = (Element) elementList.item(0);
    attributes = element.getAttributes();
    attr = (Attr) attributes.getNamedItemNS("http://www.usa.com", "domestic");
    element = (Element) elementList.item(1);
    attributes = element.getAttributes();
    {
        boolean success = false;
        try {
            attributes.setNamedItemNS(attr);
        } catch (DOMException ex) {
            success = (ex.code == DOMException.INUSE_ATTRIBUTE_ERR);
        }
        assertTrue("namednodemapsetnameditemns06", success);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 53 with NamedNodeMap

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

the class NamedNodeMapSetNamedItemNS method testSetNamedItemNS4.

public void testSetNamedItemNS4() throws Throwable {
    Document doc;
    DOMImplementation domImpl;
    Document docAlt;
    DocumentType docType = null;
    NamedNodeMap attributes;
    NodeList elementList;
    Element element;
    Attr attrAlt;
    String nullNS = null;
    doc = (Document) load("staffNS", builder);
    elementList = doc.getElementsByTagNameNS("*", "address");
    element = (Element) elementList.item(1);
    attributes = element.getAttributes();
    domImpl = doc.getImplementation();
    docAlt = domImpl.createDocument(nullNS, "newDoc", docType);
    attrAlt = docAlt.createAttributeNS(nullNS, "street");
    {
        boolean success = false;
        try {
            attributes.setNamedItemNS(attrAlt);
        } catch (DOMException ex) {
            success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
        }
        assertTrue("throw_WRONG_DOCUMENT_ERR", success);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) DocumentType(org.w3c.dom.DocumentType) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 54 with NamedNodeMap

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

the class SetNamedItemNS method testSetNamedItemNS2.

public void testSetNamedItemNS2() throws Throwable {
    String namespaceURI = "http://www.usa.com";
    String qualifiedName = "dmstc:domestic";
    Document doc;
    Document anotherDoc;
    Node arg;
    NodeList elementList;
    Node testAddress;
    NamedNodeMap attributes;
    doc = (Document) load("staffNS", builder);
    anotherDoc = (Document) load("staffNS", builder);
    arg = anotherDoc.createAttributeNS(namespaceURI, qualifiedName);
    arg.setNodeValue("Maybe");
    elementList = doc.getElementsByTagName("address");
    testAddress = elementList.item(0);
    attributes = testAddress.getAttributes();
    {
        boolean success = false;
        try {
            attributes.setNamedItemNS(arg);
        } catch (DOMException ex) {
            success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
        }
        assertTrue("throw_WRONG_DOCUMENT_ERR", success);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document)

Example 55 with NamedNodeMap

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

the class NamedNodeMapGetNamedItemNS method testGetNamedItemNS4.

public void testGetNamedItemNS4() throws Throwable {
    Document doc;
    NamedNodeMap attributes;
    Element element;
    Attr attribute;
    Attr newAttr1;
    NodeList elementList;
    String attrName;
    doc = (Document) load("staffNS", builder);
    elementList = doc.getElementsByTagNameNS("*", "address");
    element = (Element) elementList.item(1);
    newAttr1 = doc.createAttributeNS("http://www.w3.org/DOM/L1", "street");
    element.setAttributeNodeNS(newAttr1);
    attributes = element.getAttributes();
    attribute = (Attr) attributes.getNamedItemNS("http://www.w3.org/DOM/L1", "street");
    attrName = attribute.getNodeName();
    assertEquals("namednodemapgetnameditemns04", "street", attrName);
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Aggregations

NamedNodeMap (org.w3c.dom.NamedNodeMap)993 Node (org.w3c.dom.Node)690 NodeList (org.w3c.dom.NodeList)339 Attr (org.w3c.dom.Attr)295 Element (org.w3c.dom.Element)238 Document (org.w3c.dom.Document)154 ArrayList (java.util.ArrayList)92 HashMap (java.util.HashMap)91 DocumentBuilder (javax.xml.parsers.DocumentBuilder)59 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)58 IOException (java.io.IOException)53 SAXException (org.xml.sax.SAXException)41 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)40 List (java.util.List)36 Map (java.util.Map)33 File (java.io.File)27 InputStream (java.io.InputStream)26 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)25 DOMException (org.w3c.dom.DOMException)25 ByteArrayInputStream (java.io.ByteArrayInputStream)19