Example usage for org.w3c.dom Element getAttribute

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

Introduction

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

Prototype

public String getAttribute(String name);

Source Link

Document

Retrieves an attribute value by name.

Usage

From source file:org.xacml4j.spring.pdp.RequestContextHandlerChainDefinitionParser.java

private static void parseHandlers(List<Element> childElements, BeanDefinitionBuilder chain) {
    ManagedList<BeanDefinition> handlers = new ManagedList<BeanDefinition>(childElements.size());
    for (Element childElement : childElements) {
        BeanDefinitionBuilder handler = BeanDefinitionBuilder
                .rootBeanDefinition(RequestContextHandlerFactoryBean.class);
        handler.addPropertyReference("ref", childElement.getAttribute("ref"));
        handlers.add(handler.getBeanDefinition());
    }/*from w ww .  j a v  a  2s .  c  om*/
    chain.addPropertyValue("handlers", handlers);
}

From source file:Main.java

License:asdf

public static void dom(Element element) {
    element.setAttribute("newAttrName", "attrValue");
    element.setAttribute("newAttrName", "<>&\"'");
    element.removeAttribute("value");
    boolean has = element.hasAttribute("value"); // true
    System.out.println(has);/*from  w ww  .  j a va  2s .  c  om*/
    String attrValue = element.getAttribute("value"); // mydefault
    System.out.println(attrValue);
}

From source file:com.codebutler.farebot.card.Card.java

public static Card fromXml(String xml) throws Exception {
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = builder.parse(new InputSource(new StringReader(xml)));

    Element rootElement = doc.getDocumentElement();

    CardType type = CardType.class.getEnumConstants()[Integer.parseInt(rootElement.getAttribute("type"))];
    byte[] id = Utils.hexStringToByteArray(rootElement.getAttribute("id"));
    Date scannedAt = rootElement.hasAttribute("scanned_at")
            ? new Date(Long.valueOf(rootElement.getAttribute("scanned_at")))
            : new Date(0);
    switch (type) {
    case MifareDesfire:
        return DesfireCard.fromXml(id, scannedAt, rootElement);
    case CEPAS:/*w w  w.j  a va 2  s  .c o m*/
        return CEPASCard.fromXML(id, scannedAt, rootElement);
    case FeliCa:
        return FelicaCard.fromXml(id, scannedAt, rootElement);
    case MifareClassic:
        return ClassicCard.fromXml(id, scannedAt, rootElement);
    default:
        throw new UnsupportedOperationException("Unsupported card type: " + type);
    }
}

From source file:Main.java

/**
 * Finds the first (direct) child element with a given tag name and attribute.
 * //from  ww w. j a va  2 s . c o m
 * @param parent the parent element below which to search the child
 * @param tagName the (tag) name of the desired child element
 * @param attrName the name of the attribute which value must match the given value
 * @param value the attribute value to which elements are matched.
 * @return the child element if an element of that name existed, or null otherwise
 */
static public Element findFirstChildWithAttrib(Node parent, String tagName, String attrName, Object value) {
    Element elem = findFirstChild(parent, tagName);
    if (attrName == null)
        return null;
    while (elem != null) { // Check Value
        String attrValue = elem.getAttribute(attrName);
        if (attrValue == null || attrValue.length() < 1) { // Attribute is null
            if (value == null)
                break; // gefunden!
        } else { // Attribute is not null
            if (attrValue.equals(value.toString()))
                break; // gefunden!
        }
        // next
        elem = getNextSiblingElement(elem, true);
    }
    return elem;
}

From source file:com.msopentech.odatajclient.engine.data.atom.AtomDeserializer.java

public static AtomFeed feed(final Element input) {
    if (!ODataConstants.ATOM_ELEM_FEED.equals(input.getNodeName())) {
        return null;
    }//ww w. j ava  2 s .co  m

    final AtomFeed feed = new AtomFeed();

    common(input, feed);

    final List<Element> entries = XMLUtils.getChildElements(input, ODataConstants.ATOM_ELEM_ENTRY);
    for (Element entry : entries) {
        feed.addEntry(entry(entry));
    }

    final List<Element> links = XMLUtils.getChildElements(input, ODataConstants.ATOM_ELEM_LINK);
    for (Element link : links) {
        if (ODataConstants.NEXT_LINK_REL.equals(link.getAttribute(ODataConstants.ATTR_REL))) {
            feed.setNext(URI.create(link.getAttribute(ODataConstants.ATTR_HREF)));
        }
    }

    final List<Element> counts = XMLUtils.getChildElements(input, ODataConstants.ATOM_ATTR_COUNT);
    if (!counts.isEmpty()) {
        try {
            feed.setCount(Integer.parseInt(counts.get(0).getTextContent()));
        } catch (Exception e) {
            LOG.error("Could not parse $inlinecount {}", counts.get(0).getTextContent(), e);
        }
    }

    return feed;
}

From source file:com.msopentech.odatajclient.engine.data.atom.AtomDeserializer.java

private static void common(final Element input, final AtomObject object) {
    if (StringUtils.isNotBlank(input.getAttribute(ODataConstants.ATTR_XMLBASE))) {
        object.setBaseURI(input.getAttribute(ODataConstants.ATTR_XMLBASE));
    }// w w w  .j a  va  2 s . c o m

    final List<Element> ids = XMLUtils.getChildElements(input, ODataConstants.ATOM_ELEM_ID);
    if (!ids.isEmpty()) {
        object.setId(ids.get(0).getTextContent());
    }

    final List<Element> titles = XMLUtils.getChildElements(input, ODataConstants.ATOM_ELEM_TITLE);
    if (!titles.isEmpty()) {
        object.setTitle(titles.get(0).getTextContent());
    }

    final List<Element> summaries = XMLUtils.getChildElements(input, ODataConstants.ATOM_ELEM_SUMMARY);
    if (!summaries.isEmpty()) {
        object.setSummary(summaries.get(0).getTextContent());
    }

    final List<Element> updateds = XMLUtils.getChildElements(input, ODataConstants.ATOM_ELEM_UPDATED);
    if (!updateds.isEmpty()) {
        try {
            object.setUpdated(ISO_DATEFORMAT.parse(updateds.get(0).getTextContent()));
        } catch (Exception e) {
            LOG.error("Could not parse date {}", updateds.get(0).getTextContent(), e);
        }
    }
}

From source file:Main.java

public static void dupAttributes(Document doc) {
    Element root = doc.getDocumentElement();
    Element personOne = (Element) root.getFirstChild();

    Attr deptAttr = personOne.getAttributeNode("dept");
    personOne.removeAttributeNode(deptAttr);
    String deptString = deptAttr.getValue();
    personOne.setAttribute("dept", deptString + "updated");

    String mailString = personOne.getAttribute("mail");
    personOne.setAttribute("mail", mailString + "updated");

    String titleString = personOne.getAttribute("title");
    //personOne.removeAttribute("title");
    personOne.setAttribute("title", titleString + "updated");
}

From source file:com.cburch.draw.shapes.SvgReader.java

private static AbstractCanvasObject createLine(Element elt) {
    int x0 = Integer.parseInt(elt.getAttribute("x1"));
    int y0 = Integer.parseInt(elt.getAttribute("y1"));
    int x1 = Integer.parseInt(elt.getAttribute("x2"));
    int y1 = Integer.parseInt(elt.getAttribute("y2"));
    return new Line(x0, y0, x1, y1);
}

From source file:eu.stork.peps.configuration.ConfigurationReader.java

/**
 * Generate parameters.//from  www  . jav a  2s.co  m
 * 
 * @param configurationNode the configuration node
 * 
 * @return the map< string, string>
 */
private static Map<String, String> generateParam(final Element configurationNode) {

    final HashMap<String, String> parameters = new HashMap<String, String>();

    final NodeList parameterNodes = configurationNode.getElementsByTagName(NODE_PARAMETER);

    String parameterName;
    String parameterValue;

    for (int k = 0; k < parameterNodes.getLength(); ++k) {
        // for every parameter find, process.
        final Element parameterNode = (Element) parameterNodes.item(k);
        parameterName = parameterNode.getAttribute(NODE_PARAM_NAME);
        parameterValue = parameterNode.getAttribute(NODE_PARAM_VALUE);

        // verified the content.
        if (StringUtils.isBlank(parameterName) || StringUtils.isBlank(parameterValue)) {
            throw new STORKSAMLEngineRuntimeException("Error reader parameters (name - value).");
        } else {
            parameters.put(parameterName.trim(), parameterValue.trim());
        }
    }
    return parameters;
}

From source file:com.cburch.draw.shapes.SvgReader.java

private static AbstractCanvasObject createPolygon(Element elt) {
    return new Poly(true, parsePoints(elt.getAttribute("points")));
}