Java 怎么生成XML间隔样本

2019年7月29日19:37:39Java 怎么生成XML间隔样本已关闭评论 361 1051字阅读3分30秒

1.简介

Java 怎么生成XML间隔样本?——请看下文。

2.示例代码

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



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

public class Main {
    public static void main(String[] argv) throws Exception {
        double time = 2.45678;
        long tracks = 2;
        String hardware = "tah1986.com";
        boolean finalStats = true;
        generateXMLIntervalSampleCoarse(time, tracks, hardware, finalStats);
    }

    static Document doc;

    static void generateXMLIntervalSampleCoarse(double time, long tracks,
            String hardware, boolean finalStats) {
        Element element;
        Element root = doc.getDocumentElement();

        Element me;
        if (finalStats)
            me = doc.createElement("FinalSample");
        else
            me = doc.createElement("Sample");
        root.appendChild(me);
        root = me;

        element = doc.createElement("Timestamp");
        element.setTextContent(Double.toString(time));
        root.appendChild(element);

        element = doc.createElement("Hardware");
        element.setTextContent(hardware);
        root.appendChild(element);

        
        element = doc.createElement("DataAvailable");
        element.setTextContent("True");
        root.appendChild(element);

        element = doc.createElement("LaidTracks");
        element.setTextContent(Long.toString(tracks));
        root.appendChild(element);

    }
}

 
继续阅读
编程十万个怎么办