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

百拓公司做网站怎么样网站开发的体会

百拓公司做网站怎么样,网站开发的体会,中国建设银行wap网站,没有域名的网站SAX解析器使用回调函数#xff08;org.xml.sax.helpers.DefaultHandler#xff09;通知客户端XML文档结构。 您应该扩展DefaultHandler并重写一些方法来实现xml解析。 覆盖的方法是 startDocument#xff08;#xff09;和endDocument#xff08;#xff09;–在XML文档… SAX解析器使用回调函数org.xml.sax.helpers.DefaultHandler通知客户端XML文档结构。 您应该扩展DefaultHandler并重写一些方法来实现xml解析。 覆盖的方法是 startDocument和endDocument–在XML文档的开头和结尾处调用的方法。 startElement和endElement–在文档元素的开头和结尾处调用的方法。 character–以XML文档元素的开始和结束标记之间的文本内容调用的方法。 下面的示例演示使用DefaultHandler解析和XML文档。 它执行xml到模型类的映射并生成对象列表。 XML文档样本 ?xml version1.0 encodingUTF-8? catalogbook id001 langENGisbn23-34-42-3/isbnregDate1990-05-24/regDatetitleOperating Systems/titlepublisher countryUSAPearson/publisherprice400/priceauthorsauthorGanesh Tiwari/author/authors/bookbook id002isbn24-300-042-3/isbnregDate1995-05-12/regDatetitleDistributed Systems/titlepublisher countryNepalEkata/publisherprice500/priceauthorsauthorMahesh Poudel/authorauthorBikram Adhikari/authorauthorRamesh Poudel/author/authors/book /catalog Book对象的模型类用于将xml映射到对象 /*** Book class stores book information, after parsing the xml* author Ganesh Tiwari*/ public class Book {String lang;String title;String id;String isbn;Date regDate;String publisher;int price;ListString authors;public Book(){authorsnew ArrayListString();}//getters and setters } XML解析Sax的Java代码 import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List;import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory;import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; public class MySaxParser extends DefaultHandler {ListBook bookL;String bookXmlFileName;String tmpValue;Book bookTmp;SimpleDateFormat sdf new SimpleDateFormat(yy-MM-dd);public MySaxParser(String bookXmlFileName) {this.bookXmlFileName bookXmlFileName;bookL new ArrayListBook();parseDocument();printDatas();}private void parseDocument() {// parseSAXParserFactory factory SAXParserFactory.newInstance();try {SAXParser parser factory.newSAXParser();parser.parse(bookXmlFileName, this);} catch (ParserConfigurationException e) {System.out.println(ParserConfig error);} catch (SAXException e) {System.out.println(SAXException : xml not well formed);} catch (IOException e) {System.out.println(IO error);}}private void printDatas() {// System.out.println(bookL.size());for (Book tmpB : bookL) {System.out.println(tmpB.toString());}}Overridepublic void startElement(String s, String s1, String elementName, Attributes attributes) throws SAXException {// if current element is book , create new book// clear tmpValue on start of elementif (elementName.equalsIgnoreCase(book)) {bookTmp new Book();bookTmp.setId(attributes.getValue(id));bookTmp.setLang(attributes.getValue(lang));}// if current element is publisherif (elementName.equalsIgnoreCase(publisher)) {bookTmp.setPublisher(attributes.getValue(country));}}Overridepublic void endElement(String s, String s1, String element) throws SAXException {// if end of book element add to listif (element.equals(book)) {bookL.add(bookTmp);}if (element.equalsIgnoreCase(isbn)) {bookTmp.setIsbn(tmpValue);}if (element.equalsIgnoreCase(title)) {bookTmp.setTitle(tmpValue);}if(element.equalsIgnoreCase(author)){bookTmp.getAuthors().add(tmpValue);}if(element.equalsIgnoreCase(price)){bookTmp.setPrice(Integer.parseInt(tmpValue));}if(element.equalsIgnoreCase(regDate)){try {bookTmp.setRegDate(sdf.parse(tmpValue));} catch (ParseException e) {System.out.println(date parsing error);}}}Overridepublic void characters(char[] ac, int i, int j) throws SAXException {tmpValue new String(ac, i, j);}public static void main(String[] args) {new MySaxParser(catalog.xml);} } 解析输出 Book [langENG, titleOperating Systems, id001, isbn23-34-42-3, regDateThu May 24 00:00:00 NPT 1990, publisherUSA, price400, authors[Ganesh Tiwari]] Book [langnull, titleDistributed Systems, id002, isbn24-300-042-3, regDateFri May 12 00:00:00 NPT 1995, publisherNepal, price500, authors[Mahesh Poudel, Bikram Adhikari, Ramesh Poudel]] 参考在GTs Blog上 使用我们的JCG合作伙伴 Ganesh Tiwari 提供的完整代码 使用SaxParser进行XML解析 。 翻译自: https://www.javacodegeeks.com/2012/01/xml-parsing-using-saxparser-with.html
http://www.sadfv.cn/news/201480/

相关文章:

  • 网站精美排版代码品牌创意网站建设徕卡e
  • 南昌做兼职的网站榆林做网站多少钱
  • 太原网站开发公司营销网站建设定制
  • 私自做彩票网站销售犯法么网站推广攻略
  • 河南基安建设集团有限公司网站互联网科技网站
  • 株洲网站制作公司有哪些用dede做网站后台
  • 用wordpress开发网站模板手机版商城网站案例
  • 有哪些网站可以做推广包包网站方案原则
  • 什么网站能看男女做暧建筑设计服务平台
  • 二级域名网站可以做关键词优化吗公司网站建设的工具
  • 动力论坛源码网站后台地址是什么求个网站带图片素材
  • 网站营销工具网络编程就业前景
  • 网站建设标新立异腾讯做网站上传
  • excel如何做超链接网站义乌外贸网站建设公司
  • 成都网站建设 lkcms小红书笔记推广
  • 阜阳做网站的深圳建设网站龙岗网站建设
  • 高端网站建设要网页制作步骤作答题
  • 济南网站中企动力wordpress 获取头像地址
  • 庆阳网站设计wordpress图片浏览插件
  • 单页 网站 模板广州企业做网站
  • 重庆知名网站建设公司免费家装设计效果图
  • 廊坊做网站厂商定制crm客户管理系统设计
  • 是网站建设专业好网站百度指数分析
  • 广东网站建设哪里有网站未备案怎么访问
  • 网站后台修改网站首页怎么做wordpress获取token方法
  • 检察 网站建设常见的erp软件有哪些
  • 宁波搭建网站公司为什么建设厅的网站不好打开
  • 网站空间ftp企业年金个人查询官网
  • 德州公司做网站广州搜发网络科技有限公司
  • 公司网站建设怎么入账企业头像logo设计免费