Java Utililty Methods XML Attribute Create

List of utility methods to do XML Attribute Create

Description

The list of methods to do XML Attribute Create are organized into topic(s).

Method

AttrcreateAttr(Element parent, String name, Object value)
create Attr
if (value == null)
    return null;
Attr a = parent.getOwnerDocument().createAttribute(name);
a.setNodeValue(value.toString());
parent.getAttributes().setNamedItem(a);
return a;
AttrcreateAttr(String attrName, String attrValue, Document document)
create Attr
if (attrName == null || attrName.length() == 0 || attrValue == null || document == null) {
    return null;
Attr attribute = document.createAttribute(attrName);
attribute.setValue(attrValue);
return attribute;
ElementcreateAttribute(Document doc, String friendlyName, String samlNS, String samlPrefix, QName attrKey)
create Attribute
Element attrEle = doc.createElementNS(samlNS, samlPrefix + ":Attribute");
attrEle.setAttribute("Name", attrKey.getLocalPart());
attrEle.setAttribute("NameFormat", attrKey.getNamespaceURI());
if ((friendlyName != null) && (!friendlyName.trim().isEmpty())) {
    attrEle.setAttribute("FriendlyName", friendlyName);
return attrEle;
voidcreateAttribute(Document doc, String nodeName, Map map)
create Attribute
Node node = doc.getElementsByTagName(nodeName).item(0);
if (node.getNodeType() == Node.ELEMENT_NODE) {
    Element element = (Element) node;
    for (Map.Entry<String, String> entry : map.entrySet()) {
        element.setAttribute(entry.getKey(), entry.getValue());
AttrcreateAttribute(Document document, String name, String value)
create Attribute
Attr attr = document.createAttribute(name);
attr.setTextContent(value);
return attr;
voidcreateAttribute(String sName, String sValue, Node nParent)
This method creates an attribute with the given name and value.
if ((nParent != null) && (nParent instanceof Element)) {
    Element eParent = (Element) nParent;
    eParent.setAttribute(sName, sValue);
MapcreateAttributeTable(Element e)
create Attribute Table
Map<String, String> attributeTable = new HashMap<>();
NamedNodeMap attrs = e.getAttributes();
if (attrs != null) {
    int numAttrs = attrs.getLength();
    for (int i = 0; i < numAttrs; i++) {
        Node na = attrs.item(i);
        if (na.getNodeType() != Node.ATTRIBUTE_NODE) {
            continue;
...
ElementcreateFillAttributeGraphics(Document d, boolean showColor, boolean showGradientColor, boolean showGradientRotation, boolean showImage)
create Fill Attribute Graphics
Element fillGraphics = d.createElement("fill");
if (showColor)
    fillGraphics.setAttribute("color", "#FF0000");
if (showGradientColor)
    fillGraphics.setAttribute("gradient-color", "#FFFFFF");
if (showGradientRotation)
    fillGraphics.setAttribute("gradient-rotation", "diagonal");
if (showImage)
...
ElementcreateFontAttributeGraphics(Document d, boolean showFamily, boolean showStyle, boolean showWeight, boolean showSize, boolean showDecoration, boolean showAlign, boolean showRotation)
create Font Attribute Graphics
Element fontGraphics = d.createElement("font");
if (showFamily)
    fontGraphics.setAttribute("family", "arial,sans-serif");
if (showStyle)
    fontGraphics.setAttribute("style", "italic");
if (showWeight)
    fontGraphics.setAttribute("weight", "bold");
if (showSize)
...
MapmapifyAttrs(Node node, Map overwrite)
This grabs the attributes from a dom node and overwrites those values with those specified by the overwrite map.
Map<String, String> map = new HashMap<String, String>();
NamedNodeMap nnMap = node.getAttributes();
for (int i = 0; i < nnMap.getLength(); i++) {
    Node attr = nnMap.item(i);
    map.put(attr.getNodeName(), attr.getNodeValue());
if (overwrite != null) {
    for (Map.Entry<String, String> e : overwrite.entrySet()) {
...