首页 > web前端 > js教程 > 正文

往xml中更新节点的ajax方式

php中世界最好的语言
发布: 2018-04-04 11:06:59
原创
1270人浏览过

这次给大家带来往xml中更新节点的ajax方式,往xml中更新节点ajax的注意事项有哪些,下面就是实战案例,一起来看一下。

往xml中更新节点的实例代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

/* System.out.println("2323");

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder docbuilder = factory.newDocumentBuilder();

Document parse = docbuilder

.parse(new File("src/ProdQuery.xml"));

// Element createElement2 = parse.createElement("");

Element createElement = parse.createElement("products");

Node item2 = parse.getChildNodes().item(parse.getChildNodes().getLength()-1);

for (String item : map.keySet()) {

//循环添加至products

System.out.println("tianjia1");

Element clidren = parse.createElement("product");

Attr createAttribute = parse.createAttribute("name");

createAttribute.setNodeValue(item);

Attr createAttribute2 = parse.createAttribute("value");

createAttribute2.setNodeValue(map.get(item));

clidren.setAttributeNode(createAttribute);

clidren.setAttributeNode(createAttribute2);

createElement.appendChild(clidren);

}

//将products添加到根目录

item2.appendChild(createElement);

//创建一个TransformerFactory对象

TransformerFactory tFactory = TransformerFactory.newInstance();

//得到一个操作对象

Transformer transformer = tFactory.newTransformer();

//设置们,这个是编码

transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");

//

DOMSource source = new DOMSource(parse);

System.out.println("改变文件");

StreamResult result = new StreamResult(new File("src/ProdQuery.xml"));

//让xml文件换行

transformer.setOutputProperty(OutputKeys.INDENT, "yes");

transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

transformer.transform(source, result);*/

登录后复制

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

Ajax的restful接口传输Json数据的方法

Ajax+Struts2怎么实现用户输入验证码校验功能

以上就是往xml中更新节点的ajax方式的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号