package com.daewoobrenic.oa.com.xml;import java.io.FileOutputStream;import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;public class WorkFlowControl {
public void CreateWorkFlowInfo(String name ,String fileName)
{
FileOutputStream fo=null;
try
{
SAXBuilder builder=new SAXBuilder(false);
String XMLPath=System.getProperty("user.dir")+"\\WEB-INF\\classes\\workflows.xml";
Document doc=builder.build(XMLPath);
Element beans=doc.getRootElement(); Element beanElement = new Element("workflow");
beans.setContent(beanElement);
Attribute vocation1 = new Attribute("name",name);
beanElement.setAttribute(vocation1);
Attribute vocation2 = new Attribute("type", "resource");
beanElement.setAttribute(vocation2);
Attribute vocation3 = new Attribute("location", fileName);
beanElement.setAttribute(vocation2);
XMLOutputter xmlOut=new XMLOutputter();
fo = new FileOutputStream(XMLPath);
xmlOut.output(doc,fo);
fo.close();
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
try
{
fo.close();
}
catch(Exception e)
{
}
}
}
//public Step
}因为是菜鸟,,所以分析的能简单,,,让我知道怎么去应用...
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;public class WorkFlowControl {
public void CreateWorkFlowInfo(String name ,String fileName)
{
FileOutputStream fo=null;
try
{
SAXBuilder builder=new SAXBuilder(false);
String XMLPath=System.getProperty("user.dir")+"\\WEB-INF\\classes\\workflows.xml";
Document doc=builder.build(XMLPath);
Element beans=doc.getRootElement(); Element beanElement = new Element("workflow");
beans.setContent(beanElement);
Attribute vocation1 = new Attribute("name",name);
beanElement.setAttribute(vocation1);
Attribute vocation2 = new Attribute("type", "resource");
beanElement.setAttribute(vocation2);
Attribute vocation3 = new Attribute("location", fileName);
beanElement.setAttribute(vocation2);
XMLOutputter xmlOut=new XMLOutputter();
fo = new FileOutputStream(XMLPath);
xmlOut.output(doc,fo);
fo.close();
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
try
{
fo.close();
}
catch(Exception e)
{
}
}
}
//public Step
}因为是菜鸟,,所以分析的能简单,,,让我知道怎么去应用...
楼主【saj23jsak】截止到2008-07-18 08:57:00的历史汇总数据(不包括此帖):
发帖的总数量:4 发帖的总分数:400 每贴平均分数:100
回帖的总数量:3 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:2 结贴的总分数:200
无满意结贴数:0 无满意结贴分:0
未结的帖子数:2 未结的总分数:200
结贴的百分比:50.00 % 结分的百分比:50.00 %
无满意结贴率:0.00 % 无满意结分率:0.00 %
楼主加油
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;public class WorkFlowControl {
public void CreateWorkFlowInfo(String name ,String fileName)
{
FileOutputStream fo=null;
try
{
SAXBuilder builder=new SAXBuilder(false);
String XMLPath=System.getProperty("user.dir")+"\\WEB-INF\\classes\\workflows.xml";
//得到xml文件的路径
Document doc=builder.build(XMLPath);
//得到根节点
Element beans=doc.getRootElement();
//new一个新元素
Element beanElement = new Element("workflow");
//设置跟节点的content为workflow
beans.setContent(beanElement);
//设置新元素的属性
Attribute vocation1 = new Attribute("name",name);
beanElement.setAttribute(vocation1);
Attribute vocation2 = new Attribute("type", "resource");
beanElement.setAttribute(vocation2);
Attribute vocation3 = new Attribute("location", fileName);
beanElement.setAttribute(vocation2);
//输出,写入xml文件
XMLOutputter xmlOut=new XMLOutputter();
fo = new FileOutputStream(XMLPath);
xmlOut.output(doc,fo);
fo.close();
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
try
{
fo.close();
}
catch(Exception e)
{
}
}
}
//public Step
}
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;public class WorkFlowControl {
public void CreateWorkFlowInfo(String name ,String fileName)
{
FileOutputStream fo=null;
try
{
SAXBuilder builder=new SAXBuilder(false); //这表示使用的是默认的解析器
String XMLPath=System.getProperty("user.dir")+"\\WEB-INF\\classes\\workflows.xml";//得到xml文件
Document doc=builder.build(XMLPath);//得到Document,我们以后要进行的所有操作都是对这个Document操作的
Element beans=doc.getRootElement();//得到根元素,在JDOM中所有的节点(DOM中的概念)都是一个org.jdom.Element类,当然他的子节点也是一个org.jdom.Element类。 Element beanElement = new Element("workflow");//创建一个元素
beans.setContent(beanElement);
Attribute vocation1 = new Attribute("name",name);//设置元素的属性
beanElement.setAttribute(vocation1);
Attribute vocation2 = new Attribute("type", "resource");
beanElement.setAttribute(vocation2);
Attribute vocation3 = new Attribute("location", fileName);
beanElement.setAttribute(vocation2);
XMLOutputter xmlOut=new XMLOutputter();//先要有一个XMLOutputter类,保存Document的修改到XML文件中.
fo = new FileOutputStream(XMLPath);
xmlOut.output(doc,fo);//再把已经修改了的Document保存进XML文档中
fo.close();
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
try
{
fo.close();
}
catch(Exception e)
{
}
}
}
//public Step
}
综合了sax,和dom的优点!