java 通過dom4J生成xml檔案
阿新 • • 發佈:2019-01-01
樣例:
public static void main (String[] args){
Document document = DocumentHelper.createDocument();Element root = document.addElement("adi:ADI2", "http://www.cablelabs.com/VODSchema/default");
root.addNamespace("adi", "http://www.cablelabs.com/VODSchema/adi")
.addNamespace("vod", "http://www.cablelabs.com/VODSchema/vod");
Element metadata1 = root.addElement("adi:OpenGroupAsset").addAttribute("type", "VODRelease").addAttribute("product", "VOD");
Element ams = metadata1.addElement("vod:VODRelease").addAttribute("providerID", "sihua").addAttribute("providerType", "2");
Element kk1 = ams.addElement("adi:AssetLifetime").addAttribute("startDateTime", "2015-04-08 00:00:00").addAttribute("endDateTime", "2065-04-08 00:00:00").addCDATA("測試1");
Element kk2 = ams.addElement("vod:ShowType").addAttribute("ceshi", "123").addCDATA("");
log.info(document.asXML());
}
maven需要的jar包:
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>