当前位置: 首页 > news >正文

在线做logo印章网站制图软件免费

在线做logo印章网站,制图软件免费,网站建设的主要工作有哪些,大型网站制作导图工作需要#xff0c;要生成xml文件#xff0c;所以做了个小demo分享一下。看代码吧~ main()里面没什么好说的 该写的都写了public static void main(String[] args) {//调用 DocumentBuilderFactory.newInstance() 方法得到创建 DOM 解析器的工厂DocumentBuilderFactory fact…工作需要要生成xml文件所以做了个小demo分享一下。看代码吧~ main()里面没什么好说的 该写的都写了public static void main(String[] args) {//调用 DocumentBuilderFactory.newInstance() 方法得到创建 DOM 解析器的工厂DocumentBuilderFactory factoryDocumentBuilderFactory.newInstance();Element theBooknull, theElemnull, rootnull;try {factory.setIgnoringElementContentWhitespace(true);//是否删除空格 false trueDocumentBuilder dbfactory.newDocumentBuilder(); //获取解析器//指定路径 获取xml文件的document对象File f new File(src/book.xml);Document xmldocdb.parse(f);rootxmldoc.getDocumentElement();//添加 元素(节点)theBookxmldoc.createElement(book1);theElemxmldoc.createElement(name);theElem.setTextContent(平凡的世界);theBook.appendChild(theElem);theElemxmldoc.createElement(price);theElem.setTextContent(55.0);theBook.appendChild(theElem);theElemxmldoc.createElement(conment);theElem.setTextContent(推荐大家看看这本书);theBook.appendChild(theElem);root.appendChild(theBook);printXML(xmldoc);//打印至ConsolesaveXml(new_book.xml, xmldoc);//保存生成 xml文件} catch (ParserConfigurationException e) {e.printStackTrace();} catch (SAXException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}方法printXML() 打印到Console1.下面的方法中得到的transFactory对象调用newTransformer()方法得到一个Transformer对象Transformer transformertransFactory. newTransformer();Transformer类在javax.xml.transform包中。将被变换的Document对象封装到一个DOMSource对象中DOMSource  domSourcenew DOMSource(document);DOMSource类在javax.xml.transform.dom包中。将变换得到XML文件对象封装到一个StreamResult对象中File filenew File(XXX.xml);FileOutputStream outnew FileOutputStream(file);StreamResult xmlResultnew StreamResult(out);StreamResult类在javax.xml.transform.stream包中。最后Transformer 对象transformer 调用transform方法实施变换transformer.transform(domSource, xmlResult);2.transformer.setOutputProperty(indent,yes);这里比较无语 只给了 是否设置缩进 只有yes|no你选择的是yes也就等于格式化了xml效果如下默认缩进的是0关于这个缩进问题 我还没处理好呢这里给个参考链接吧:http://blog.csdn.net/yes1983/article/details/2487455(ps:要是不在乎这个的话可以放弃这一步)public static void printXML(Node node) {TransformerFactory transFactoryTransformerFactory.newInstance();try {Transformer transformer transFactory.newTransformer();transformer.setOutputProperty(encoding, gb2312);//指定编码transformer.setOutputProperty(indent, yes); //是否设置缩进DOMSource sourcenew DOMSource();source.setNode(node);StreamResult resultnew StreamResult();result.setOutputStream(System.out);transformer.transform(source, result);} catch (TransformerConfigurationException e) {e.printStackTrace();} catch (TransformerException e) {e.printStackTrace();}}方法:saveXml() 保存生成xml文件public static void saveXml(String fileName, Document doc) {TransformerFactory transFactoryTransformerFactory.newInstance();try {Transformer transformer transFactory.newTransformer();transformer.setOutputProperty(indent, yes);//是否设置缩进DOMSource sourcenew DOMSource();source.setNode(doc);StreamResult resultnew StreamResult();result.setOutputStream(new FileOutputStream(fileName));transformer.transform(source, result);} catch (TransformerConfigurationException e) {e.printStackTrace();} catch (TransformerException e) {e.printStackTrace();} catch (FileNotFoundException e) {e.printStackTrace();}}运行结果:生成的新的xml文件内容最后我想说一下编码 开始的时候一定要统一编码 不然生成的xml文件会乱码的由最代码官方编辑于2014-8-14 16:44:29
http://www.pierceye.com/news/32441/

相关文章:

  • 做公司网站找谁作一手房用什么做网站
  • 南宁品牌网站建设网站几个模板最好
  • 手机网站开发免费视频教程网站建设优化哪家公司好
  • 怎么开网站做站长长春网站制作外包
  • 环保网站模板代码格尔木哪里有做网站的
  • 婚纱摄影网站的设计与实现论文wap网站后台模板
  • 南昌网站建设制作商食品包装设计理念
  • 购物网站的设计思路网页美工设计书本
  • 网站模块制作WordPress按评论时间排序
  • 网站除了域名还要什么做网站用什么后缀好
  • 站长工具劲爆中国商机创业网
  • 网站前面的小图标怎么做佛山厂家关键词网络推广
  • 制作网站要多久毕业设计代做网站机械
  • 苏州免费网站建设莆田网站建设
  • 网站推广昔年下拉网站建设方案书生鲜
  • 哈尔滨自助建站模板广州海珠区发布
  • 万网icp网站备案专题做网店好还是自己建网站好
  • 素马网站设计公司没有网站的域名
  • 高仿酒网站怎么做教育 wordpress模板下载地址
  • 专业营销网站开发新手如何做好网络营销推广
  • 土木特网站建设以家乡为主题做网站
  • 网站推销策划方案做旅游网站有前途吗
  • 国外网站建设的研究现状成立公司需要多少注册资金
  • 网站布局设计步骤小红门网站建设
  • 基于c 的网站开发注册个app要多少钱
  • 宁阳移动网站制作用本机做网站浏览
  • 高端的电影网站怎么把自己的网站推广出去
  • 12个 网站模板 管理wordpress系统邮箱地址
  • 市场体系建设司在官方网站wordpress说说伪静态
  • 深圳做网站建设和维护专员管理层wordpress文学站