日期:2014-05-20  浏览次数:20793 次

怎么生成一个这样的结构的xml啊,,,,帮我看看吧,整一下午了
<content>12<sup>2</sup>34</content>
我现在写了这样的代码,那后面的34怎么加进去啊
Element content = document.createElement("content");
content.setTextContent("25");
Element sup = document.createElement("sup");
sup.setTextContent("2");
content.appchild(sup);

------最佳解决方案--------------------
哦,用了Java自带的,那么:

Text t2 = document.createTextNode("34");
content.appendChild(t2);
------其他解决方案--------------------
不懂你的格式,你这种格式只有自己定义了生成好像不行。用java的字符来处理吧


------其他解决方案--------------------
用的是什么组件来生成XML的?

要增加“文本”节点,在XML中,文本其实也是一种节点。
------其他解决方案--------------------
对,那个格式是自定义的,但是如果用字符串写入文件,“<”号编程了“&lt;”
这个怎么办啊?  怎么写入“<”啊?
------其他解决方案--------------------
引用:
用的是什么组件来生成XML的?

要增加“文本”节点,在XML中,文本其实也是一种节点。

用的是DocumentBuilderFactory这个。。
现在前面的写入来<content>里面了  但是那个34不知道怎么加在后面
------其他解决方案--------------------
给你看一下我处理的


/**
 * 功能:生成下载配置文件
 * */
@SuppressWarnings("unchecked")
public StringBuffer buildTemplate(Object[] htmlTag,String template,String downloadPath,String shellBasePath,String shellId){
HashMap<String,String> headMap = (HashMap<String,String>)htmlTag[0];
ArrayList<HashMap<String,String>> bodyList = (ArrayList<HashMap<String,String>>)htmlTag[1];
StringBuffer downloadConfig = new StringBuffer();
if(downloadPath.indexOf(downloadPath.length()-1) == -1){
downloadPath = downloadPath + File.separator;
}
for(Iterator<HashMap<String,String>> it = bodyList.iterator();it.hasNext();){
HashMap<String,String> bodyMap = it.next();
StringBuffer config = new StringBuffer()
.append(template.replace("{nTag}", bodyMap.get("<N>"))//<N>
.replace("{pTag}", bodyMap.get("<P>") == null ? "" : bodyMap.get("<P>"))//<P>
.replace("{fTag}", headMap.get("<F>") == null ? "" : headMap.get("<F>"))//<F>
.replace("{xTag}", bodyMap.get("<X>") == null ? "" : bodyMap.get("<X>"))//<X>
.replace("{uTag}", bodyMap.get("<U>") == null ? "" : bodyMap.get("<U>"))//<U>
.replace("{cTag}", bodyMap.get("<C>") == null ? "" : bodyMap.get("<C>"))//<C>
.replace("{peTag}", bodyMap.get("<PE>") == null ? "" : bodyMap.get("<PE>"))//<PE>
.replace("{usTag}", bodyMap.get("<US>") == null ? "" : bodyMap.get("<US>"))//<PE>
.replace("{ueTag}", bodyMap.get("<UE>") == null ? "" : bodyMap.get("<UE>"))//<PE>
.replace("{explodeIdTag}", bodyMap.get("<EXPLODEID>") == null ? "" : bodyMap.get("<EXPLODEID>"))
.replace("{sTag}", downloadPath)//下载路径
.replace("{bTag}", shellBasePath) //生成下载文件脚本地址