jdom 修改xml文件 保存


1 /*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6 package analyzewdsl;
7
8 import java.io.File;
9 import java.io.FileOutputStream;
10 import java.io.IOException;
11 import java.net.URLDecoder;
12 import java.util.logging.Level;
13 import java.util.logging.Logger;
14 import org.jdom.Document;
15 import org.jdom.Element;
16 import org.jdom.JDOMException;
17 import org.jdom.input.SAXBuilder;
18 import org.jdom.output.XMLOutputter;
19 import org.jdom.xpath.XPath;
20
21 /**
22 *
23 * @author root
24 */
25 public class Main {
26
27 private Document doc;
28
29 private Element element;
30
31
32
33 public static void main(String[] args) {
34 new Main().wsdl();
35 }
36
37 /**
38 * @param args the command line arguments
39 */
40 public void wsdl() {
41 // TODO code application logic here
42
43 SAXBuilder builder=new SAXBuilder();
44 try {
45
46
47 String currentJarPath = URLDecoder.decode(Main.class.getProtectionDomain().getCodeSource().getLocation().getFile()+"!Hello.wsdl", "UTF-8");
48 System.out.println(currentJarPath);
49
50 doc = builder.build(currentJarPath);
51 element=doc.getRootElement();
52
53 Element e=(Element)XPath.selectSingleNode(element, "//xsd:import");
54
55
56 e.setAttribute("schemaLocation", "aaa");
57 System.out.println(e.getAttributeValue("schemaLocation").toString());
58
59
60 XMLOutputter out = new XMLOutputter();
61
62 // String s=this.getClass().getResource("/").toString();
63 // System.out.println(s);
64 //
65 out.output(doc,new FileOutputStream(new File(currentJarPath.replaceAll("file:",""))));
66
67 } catch (JDOMException ex) {
68 Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
69 } catch (IOException ex) {
70 Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
71 }
72 }
73
74 }
75
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值