Search in sources :

Example 86 with Attr

use of org.w3c.dom.Attr 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 87 with Attr

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

the class NodeIsSupported method testIsSupported2.

public void testIsSupported2() throws Throwable {
    Document doc;
    Attr attribute;
    String version = "";
    String version1 = "1.0";
    String version2 = "2.0";
    String featureCore;
    String featureXML;
    boolean success;
    List<String> featuresXML = new ArrayList<String>();
    featuresXML.add("XML");
    featuresXML.add("xmL");
    List<String> featuresCore = new ArrayList<String>();
    featuresCore.add("Core");
    featuresCore.add("CORE");
    doc = (Document) load("staffNS", builder);
    attribute = doc.createAttribute("TestAttr");
    for (int indexN10064 = 0; indexN10064 < featuresXML.size(); indexN10064++) {
        featureXML = (String) featuresXML.get(indexN10064);
        success = attribute.isSupported(featureXML, version);
        assertTrue("nodeissupported02_XML1", success);
        success = attribute.isSupported(featureXML, version1);
        assertTrue("nodeissupported02_XML2", success);
    }
    for (int indexN1007D = 0; indexN1007D < featuresCore.size(); indexN1007D++) {
        featureCore = (String) featuresCore.get(indexN1007D);
        success = attribute.isSupported(featureCore, version);
        assertTrue("nodeissupported02_Core1", success);
        success = attribute.isSupported(featureCore, version1);
        success = attribute.isSupported(featureCore, version2);
        assertTrue("nodeissupported02_Core3", success);
    }
}
Also used : ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 88 with Attr

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

the class NodeSetPrefix method testSetPrefix7.

public void testSetPrefix7() throws Throwable {
    Document doc;
    Attr attribute;
    doc = (Document) load("staffNS", builder);
    attribute = doc.createAttributeNS("http://www.w3.org/DOM/Test/L2", "abc:elem");
    {
        boolean success = false;
        try {
            attribute.setPrefix("xmlns");
        } catch (DOMException ex) {
            success = (ex.code == DOMException.NAMESPACE_ERR);
        }
        assertTrue("throw_NAMESPACE_ERR", success);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 89 with Attr

use of org.w3c.dom.Attr 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 90 with Attr

use of org.w3c.dom.Attr 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)

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