Example usage for org.w3c.dom Element getAttributes

List of usage examples for org.w3c.dom Element getAttributes

Introduction

In this page you can find the example usage for org.w3c.dom Element getAttributes.

Prototype

public NamedNodeMap getAttributes();

Source Link

Document

A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.

Usage

From source file:org.esipfed.eskg.aquisition.PODAACWebServiceClient.java

/**
 * This function accepts the result of querying the PO.DAAC Dataset Search
 * WebService using the query provided in the DATASET_SEARCH constant. The
 * response is in Atom XML, from each entry result, we therefore simply
 * extract all instances of 'podaac:datasetId' and add these to an ArrayList.
 * We use this List to obtain GMCD Metadata for each dataset.
 * // ww  w.  j a v  a  2s . c  o m
 * @param byteArrayInputStream
 * @return
 */
private List<String> parseDatasetSearchAtomXML(ByteArrayInputStream byteArrayInputStream) {
    List<String> datasetGCMDList = new ArrayList<>();
    try {

        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(byteArrayInputStream);
        doc.getDocumentElement().normalize();
        Element root = doc.getDocumentElement();
        NodeList firstChildNodes = root.getChildNodes();

        for (int i = 0; i < firstChildNodes.getLength(); i++) {
            if ("entry".equals(firstChildNodes.item(i).getNodeName())) {
                Node entryNode = firstChildNodes.item(i);

                if (entryNode.getNodeType() == Node.ELEMENT_NODE) {

                    Element entryElement = (Element) entryNode;
                    NodeList entryElementChildren = entryElement.getChildNodes();
                    for (int j = 0; j < entryElementChildren.getLength(); j++) {
                        Node entryElementChild = entryElementChildren.item(j);
                        if ("link".equals(entryElementChild.getNodeName())) {
                            Element linkNode = (Element) entryElementChild;
                            if (linkNode.getAttribute("title") != null
                                    && linkNode.getAttribute("title").contentEquals("GCMD Metadata")) {
                                String gcmdHrefValue = linkNode.getAttributes().getNamedItem("href")
                                        .getNodeValue();
                                datasetGCMDList.add(gcmdHrefValue);
                                LOG.info("Added new Dataset record to list: {}", gcmdHrefValue);
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Error whilst parsing Atom XML response from Dataset Search: ", e);
    }
    LOG.info("Total number of dataset's retrieved: {}", datasetGCMDList.size());
    return datasetGCMDList;
}

From source file:com.espertech.esper.client.ConfigurationParser.java

private static void handleEventTypes(Configuration configuration, Element element) {
    String name = getRequiredAttribute(element, "name");
    Node classNode = element.getAttributes().getNamedItem("class");

    String optionalClassName = null;
    if (classNode != null) {
        optionalClassName = classNode.getTextContent();
        configuration.addEventType(name, optionalClassName);
    }//from ww w. j  a v  a2  s  .  c  om

    handleEventTypeDef(name, optionalClassName, configuration, element);
}

From source file:net.sf.jclal.experiment.ExperimentBuilder.java

private int expandElementsIterateAttributes(Element element) {
    NamedNodeMap attributes = element.getAttributes();

    for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);

        if (attribute.getNodeName().equals("multi")) {
            combinationBase.add(element.getElementsByTagName(element.getNodeName()).getLength());
            return 1;
        }/*from w  ww.  j  a  v  a 2  s. co m*/
    }

    return 0;
}

From source file:net.sf.jclal.experiment.ExperimentBuilder.java

private int expandAttributesIterateAttributes(Element element) {
    NamedNodeMap attributes = element.getAttributes();

    for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);

        if (attribute.getNodeValue().equals("multi")) {
            combinationBase.add(element.getElementsByTagName(attribute.getNodeName()).getLength());
            return 1;
        }//from  w ww  .  j ava  2  s  .c  om
    }

    return 0;
}

From source file:microsoft.exchange.webservices.data.core.EwsServiceXmlWriter.java

/**
 * @param element DOM element//from  w w  w  .  j a va2s  .c  o  m
 * @param writer XML stream writer
 * @throws XMLStreamException the XML stream exception
 */
public static void addElement(Element element, XMLStreamWriter writer) throws XMLStreamException {
    String nameSpace = element.getNamespaceURI();
    String prefix = element.getPrefix();
    String localName = element.getLocalName();
    if (prefix == null) {
        prefix = "";
    }
    if (localName == null) {
        localName = element.getNodeName();

        if (localName == null) {
            throw new IllegalStateException("Element's local name cannot be null!");
        }
    }

    String decUri = writer.getNamespaceContext().getNamespaceURI(prefix);
    boolean declareNamespace = decUri == null || !decUri.equals(nameSpace);

    if (nameSpace == null || nameSpace.length() == 0) {
        writer.writeStartElement(localName);
    } else {
        writer.writeStartElement(prefix, localName, nameSpace);
    }

    NamedNodeMap attrs = element.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Node attr = attrs.item(i);

        String name = attr.getNodeName();
        String attrPrefix = "";
        int prefixIndex = name.indexOf(':');
        if (prefixIndex != -1) {
            attrPrefix = name.substring(0, prefixIndex);
            name = name.substring(prefixIndex + 1);
        }

        if ("xmlns".equals(attrPrefix)) {
            writer.writeNamespace(name, attr.getNodeValue());
            if (name.equals(prefix) && attr.getNodeValue().equals(nameSpace)) {
                declareNamespace = false;
            }
        } else {
            if ("xmlns".equals(name) && "".equals(attrPrefix)) {
                writer.writeNamespace("", attr.getNodeValue());
                if (attr.getNodeValue().equals(nameSpace)) {
                    declareNamespace = false;
                }
            } else {
                writer.writeAttribute(attrPrefix, attr.getNamespaceURI(), name, attr.getNodeValue());
            }
        }
    }

    if (declareNamespace) {
        if (nameSpace == null) {
            writer.writeNamespace(prefix, "");
        } else {
            writer.writeNamespace(prefix, nameSpace);
        }
    }

    NodeList nodes = element.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node n = nodes.item(i);
        writeNode(n, writer);
    }

    writer.writeEndElement();

}

From source file:com.amalto.workbench.dialogs.ValidationRuleDialog.java

private List<Line> parseRules() {
    List<Line> lines = new ArrayList<Line>();
    pattern = pattern.replaceAll("\\r\\n|\\n", "");//$NON-NLS-1$//$NON-NLS-2$
    String context = "";//$NON-NLS-1$
    String type = "";//$NON-NLS-1$
    String express = "";//$NON-NLS-1$
    String msg = "";//$NON-NLS-1$
    Element e = null;
    try {/*from www.ja v  a  2 s .co  m*/
        e = Util.parse(pattern).getDocumentElement();
    } catch (Exception e1) {

        log.error(e1.getMessage(), e1);

    }
    if (e.getAttributes().getNamedItem("name") != null) { //$NON-NLS-1$
        name = e.getAttributes().getNamedItem("name").getTextContent();//$NON-NLS-1$
    }
    text.setText("Product Type".equals(name) ? "" : name);//$NON-NLS-1$//$NON-NLS-2$

    ckName = name;
    NodeList rulelist = e.getElementsByTagName("rule");//$NON-NLS-1$
    for (int i = 0; i < rulelist.getLength(); i++) {
        Node r = rulelist.item(i);
        context = r.getAttributes().getNamedItem("context").getTextContent();//$NON-NLS-1$
        for (int j = 0; j < r.getChildNodes().getLength(); j++) {
            if (r.getChildNodes().item(j).getNodeType() == Node.ELEMENT_NODE) {
                type = r.getChildNodes().item(j).getNodeName();
                express = r.getChildNodes().item(j).getAttributes().getNamedItem("test").getTextContent();//$NON-NLS-1$
                msg = r.getChildNodes().item(j).getTextContent();
                break;
            }
        }

        Line l = new Line(columns, new String[] { type, context, express, msg });
        lines.add(l);
    }

    return lines;
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static boolean isPrefixUsed(Element targetElement, String prefix) {
    if (comparePrefix(prefix, targetElement.getPrefix())) {
        return true;
    }//from   w  w w  .j  a va 2s  .  c  om
    NamedNodeMap attributes = targetElement.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);
        if (comparePrefix(prefix, attr.getPrefix())) {
            return true;
        }
    }
    NodeList childNodes = targetElement.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node instanceof Element) {
            Element element = (Element) node;
            if (isPrefixUsed(element, prefix)) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.centeractive.ws.builder.soap.XmlUtils.java

public static boolean hasContentAttributes(Element elm) {
    NamedNodeMap attributes = elm.getAttributes();
    for (int c = 0; c < attributes.getLength(); c++) {
        Node item = attributes.item(c);
        String ns = item.getNamespaceURI();
        if (!ns.equals(Constants.XML_NS)
        // && !ns.equals( Constants.XSI_NS ) && !ns.equals(
        // Constants.XSI_NS_2000 )
        // && !ns.equals( Constants.XSD_NS )
        )/*from  w  w w  .  j ava 2  s.  co m*/
            return true;
    }

    return false;
}

From source file:net.sf.jclal.experiment.ExperimentBuilder.java

private int expandAttributesIterateAtributes(Element element, int[] configurationSchema) {
    NamedNodeMap attributes = element.getAttributes();

    for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);

        if (attribute.getNodeValue().equals("multi")) {
            NodeList list = element.getElementsByTagName(attribute.getNodeName());

            for (int j = 0; j < configurationSchema.length; j++) {
                if (configurationSchema[j] != -1) {
                    attribute.setNodeValue(list.item(configurationSchema[j]).getFirstChild().getNodeValue());
                    configurationSchema[j] = -1;
                    break;
                }/* w  ww .j  a  v a  2s  .  co m*/
            }

            list = element.getChildNodes();

            for (int j = 0; j < list.getLength(); j++) {
                if (list.item(j).getNodeName().equals(attribute.getNodeName())) {
                    element.removeChild(list.item(j));
                }
            }

            return 1;
        }
    }

    return 0;
}

From source file:net.sf.jclal.experiment.ExperimentBuilder.java

private int expandElementsIterateAtributes(Element element, int[] configurationSchema) {
    NamedNodeMap attributes = element.getAttributes();

    for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);

        if (attribute.getNodeName().equals("multi")) {
            NodeList list = element.getElementsByTagName(element.getNodeName());

            for (int j = 0; j < configurationSchema.length; j++) {
                if (configurationSchema[j] != -1) {
                    element.getParentNode().replaceChild(list.item(configurationSchema[j]), element);

                    configurationSchema[j] = -1;
                    break;
                }/*from  w w  w  .j  av a 2 s .co  m*/
            }

            list = element.getChildNodes();

            for (int j = 0; j < list.getLength(); j++) {
                if (list.item(j).getNodeName().equals(attribute.getNodeName())) {
                    element.removeChild(list.item(j));
                }
            }

            return 1;
        }
    }

    return 0;
}