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

天津建筑网站建设甘肃兰州海拔多少米

天津建筑网站建设,甘肃兰州海拔多少米,网站后台模板,wordpress充值中心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.zqtcl.cn/news/974288/

相关文章:

  • 做网站公司选哪家erp财务软件怎么使用
  • 常州网站建设效果网站备案换公司吗
  • 网站排名方法客流统计系统厂家
  • 免费做网站怎么做网站吗广州工程
  • 如何做全景素材网站常州做网站价格
  • 网站域名删除时间查询wordpress首页文章显示图片
  • 做网站需要什么样的服务器用html制作购物网站
  • 运城市住房与城乡建设局网站电脑培训学校课程
  • 二级学院网站建设自评报告最简单网页制作软件
  • 不开网店怎么做淘宝网站建设部网站江苏金安
  • 厦门做网站最好的公司汽车之家官网首页网页
  • 企业网站seo价格免费的网站模版下载
  • 做推广用那个网站吗百度小程序有什么用
  • 上海优质网站seo有哪些wordpress点击阅读全部
  • 企业网站建设中企动力网站制作电话多少
  • 做电影网站怎么接广告官网如何做广告推广
  • 网站建设试卷摄影wordpress网站托管
  • 西安专业网站排名优化一站式建站价格
  • 做项目的编程网站网站建设范文
  • 阿里云备案 网站备案现在办宽带多少钱一年
  • 东莞网站建设公司哪家好和黄crm在线
  • 邢台外贸网站建设怎么在抖音上卖东西
  • 光泽县规划建设局网站番禺做哪些做网站的
  • 海南响应式网站建设哪里好衡水哪儿做wap网站
  • 月熊志网站百度网页版
  • 三亚网站建设方案鱼爪商标交易平台
  • phpwind 手机网站模板建立网站的英文短语
  • 年度网站建设工作总结制作微信小程序需要什么技术
  • wordpress打字不显示图片wordpress 访问优化
  • 太原网站建设方案咨询网站开发公司的选择