Java 怎么向XML文档(Document)添加字体属性

2019年7月29日19:28:22Java 怎么向XML文档(Document)添加字体属性已关闭评论 623 721字阅读2分24秒

1.简介

Java 怎么向XML文档(Document)添加字体属性?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */



import java.awt.Font;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Main {
    public static final String PROPERTY_NODE = "property";
    public static final String NAME_ATTR = "name";
    public static final String FONT_ATTR = "fontvalue";

    public static void addFontProperty(Document document, Element parent,
            String name, Font value) {
        addPropertyNode(document, parent, name).setAttribute(
                FONT_ATTR,
                value.getName() + "," + value.getStyle() + ","
                        + value.getSize());
    }

    private static Element addPropertyNode(Document document,
            Element parent, String name) {
        Element element = document.createElement(PROPERTY_NODE);
        parent.appendChild(element);
        element.setAttribute(NAME_ATTR, name);
        return element;
    }
}

 
编程十万个怎么办