JAVA 如何接收xml 一个JAVA程序怎么接收外部xml文件,然后怎样解析xml文件 ,哪人位可以给我指点一下,谢谢, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Socket, 把XML 在网络中传送 使用socket,用流获取。然后使用StAX解析。 import java.io.File;import java.io.IOException;import javax.xml.parsers.*;import org.xml.sax.*;import org.xml.sax.helpers.DefaultHandler;public class SAXPrinter extends DefaultHandler{ public void startDocument() throws SAXException { //输出XML声明。 System.out.println("<?xml version='1.0' encoding='GBK'?>"); } public void processingInstruction(String target,String data) throws SAXException { //输出文档中的处理指令。 System.out.println("<?"+target+" "+data+"?>"); } public void startElement(String uri,String localName, String qName,Attributes attrs) throws SAXException { //输出元素的开始标记及其属性。 System.out.print("<"+qName); int len=attrs.getLength(); for (int i = 0; i < len; i++) { System.out.print(" "); System.out.print(attrs.getQName(i)); System.out.print("=\""); System.out.print(attrs.getValue(i)); System.out.print("\""); } System.out.print(">"); } public void characters(char[] ch,int start,int length) throws SAXException { //输出元素的字符数据内容。 System.out.print(new String(ch,start,length)); } public void endElement(String uri,String localName,String qName) throws SAXException { //输出元素的结束标记。 System.out.print("</"+qName+">"); } public static void main(String[] args) { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp=null; try { sp = spf.newSAXParser(); File file=new File("students.xml"); sp.parse(file,new SAXPrinter()); } catch(ParserConfigurationException e){e.printStackTrace();} catch(SAXException e){e.printStackTrace();} catch(IOException e){e.printStackTrace();} }}//--------------students.xml------------------<?xml version="1.0" encoding="GB2312"?><?xml-stylesheet type="text/xsl" href="students.xsl"?><students> <student sn="01"> <name>张三</name> <age>18</age> </student> <student sn="02"> <name>李四</name> <age>20</age> </student></students> 建议用http得到xml,再用dom解析 请参考马士兵视频教程SPRING部分的前8个视频. rabbitmq消息真的可以持久化吗 达人们,帮帮小弟吧,在线等,请不吝赐教 要写一套自己的MVC框架(如:struts,spring等)需具备哪些条件? struts2.0 配置问题 求懂wirdfire(openfire)的兄弟做兼职 求助!保存数据出现SQL insert, update or delete failed (row not found)错误 在SPRING自动代理事务中.怎样让指定的拦截器对应指定的目标BEAN? 请问在哪了能下载到EJB容器的linux版本,并且如何安装 一道面试题。。感觉挺好玩的 有没有简单的解决方法 spring表单提交时间类型 为什么调用JCE加密明文之后输出的密文是乱码? struts2出错
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货