Java XML Attribute Add addAttribute(Document document, Node node, String attName, String attValue)

Here you can find the source of addAttribute(Document document, Node node, String attName, String attValue)

Description

add Attribute

License

Open Source License

Declaration

public static void addAttribute(Document document, Node node, String attName, String attValue) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Attr;

import org.w3c.dom.Document;

import org.w3c.dom.Node;

public class Main {
    public static void addAttribute(Document document, Node node, String attName, boolean attValue) {
        addAttribute(document, node, attName, attValue ? "true" : "false");
    }//w  w  w. ja  v a 2  s  .  c  om

    public static void addAttribute(Document document, Node node, String attName, int attValue) {
        addAttribute(document, node, attName, Integer.toString(attValue));
    }

    public static void addAttribute(Document document, Node node, String attName, String attValue) {
        Attr attr = document.createAttribute(attName);
        attr.setNodeValue(removeXMLInvalidChars(attValue));
        node.getAttributes().setNamedItem(attr);
    }

    public static String removeXMLInvalidChars(String input) {
        String xml10pattern = "[^" + "\u0009\r\n" + "\u0020-\uD7FF" + "\uE000-\uFFFD" + "\ud800\udc00-\udbff\udfff"
                + "]";

        return input.replaceAll(xml10pattern, "");
    }
}

Related

  1. addAttribute(Document doc, Element node, String name, String value)
  2. addAttribute(Document doc, Element parent, String attribute, Object value)
  3. addAttribute(Document doc, Node parentNode, String name, String content)
  4. addAttribute(Document doc, org.w3c.dom.Element e, String index, String value)
  5. addAttribute(Document doc, String name, Element e, String value)
  6. addAttribute(Document document, Node node, String name, String value)
  7. addAttribute(Document document, String AttribName, String attribValue, Element element)
  8. addAttribute(Document xmlDoc, Node node, String attrName, String attrValue)
  9. addAttribute(Element el, String name, String val)