关于jdom怎么解析XML流 大侠门帮帮忙:关于jdom怎么解析XML流,我之前用jdom解析的是XML文件,现在要解析xml流要怎么解析?(我试过把原来解析文件的参数Document read_doc=builder.build("Assist.xml")改成Document read_doc=builder.build(str) str是XML流字符串型式,解析会出错,请问要怎么解析?) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 SAXBuilder builder=new SAXBuilder(); Document read_doc=builder.build("agAssistgetBulletin.xml"); Element root=read_doc.getRootElement(); Element cont = root.getChild("Content"); List list=cont.getChildren("Bulletin"); for(int i=0;i<list.size();i++){ Element e=(Element)list.get(i); String bull_name=e.getChildText("Subject"); String bull_dept=e.getChildText("PublishDept"); String bull_date=e.getChildText("PublishDate"); System.out.println("---------Bulletin--------------"); System.out.println("NAME:"+bull_name); System.out.println("DEPT:"+bull_dept); System.out.println("DATE:"+bull_date); System.out.println("------------------------------"); System.out.println();这是偶解析XML文件的函数,解析XML流,要怎么写?(帮帮忙,急) import java.io.FileInputStream;import java.io.IOException;import java.io.FileNotFoundException;import org.jdom.Document;import org.jdom.Element;import org.jdom.JDOMException;import org.jdom.adapters.XercesDOMAdapter;import org.jdom.input.DOMBuilder;import org.jdom.output.XMLOutputter;import java.util.List;import java.util.Iterator; public class JDOMCreateExample1 { private static DOMBuilder builder = null; public static void main(String args[]) throws IOException,FileNotFoundException { XercesDOMAdapter xercAdapter = new XercesDOMAdapter(); org.w3c.dom.Document w3Dom = xercAdapter.getDocument(new FileInputStream("test.xml"),false); builder = new DOMBuilder("org.jdom.adapters.XercesDOMAdapter"); Document doc = builder.build(w3Dom); List childs = doc.getRootElement().getChildren("elementtest"); Iterator itr = childs.iterator(); while (itr.hasNext()) { Element child = (Element)itr.next(); System.out.println(child.getText()); } } } IO流的一编程题 求助--在线等 请教下java C/S聊天室几个问题~~ JAVA反射机制 如何调用私有类中的方法 如果把byte[]数组转化为String类型的?有什么方法? 提问:if(false == booleanXX){} and if(booleanXX == false){}有什么区别? 一个关于swing的问题!! jdk问题 如何让一个类Proxy.newProxyInstance时不出错? 如何获得一个文件得全路径 为什么java组的分数都那么低 swing中出现中文方框问题 大家说我现在应该学点什么好。。
Document read_doc=builder.build("agAssistgetBulletin.xml");
Element root=read_doc.getRootElement();
Element cont = root.getChild("Content");
List list=cont.getChildren("Bulletin");
for(int i=0;i<list.size();i++){
Element e=(Element)list.get(i);
String bull_name=e.getChildText("Subject");
String bull_dept=e.getChildText("PublishDept");
String bull_date=e.getChildText("PublishDate");
System.out.println("---------Bulletin--------------");
System.out.println("NAME:"+bull_name);
System.out.println("DEPT:"+bull_dept);
System.out.println("DATE:"+bull_date);
System.out.println("------------------------------");
System.out.println();
这是偶解析XML文件的函数,解析XML流,要怎么写?(帮帮忙,急)
import java.io.IOException;
import java.io.FileNotFoundException;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.adapters.XercesDOMAdapter;
import org.jdom.input.DOMBuilder;
import org.jdom.output.XMLOutputter;
import java.util.List;
import java.util.Iterator;
public class JDOMCreateExample1 {
private static DOMBuilder builder = null;
public static void main(String args[]) throws IOException,FileNotFoundException {
XercesDOMAdapter xercAdapter = new XercesDOMAdapter();
org.w3c.dom.Document w3Dom = xercAdapter.getDocument(new FileInputStream("test.xml"),false);
builder = new DOMBuilder("org.jdom.adapters.XercesDOMAdapter"); Document doc = builder.build(w3Dom);
List childs = doc.getRootElement().getChildren("elementtest");
Iterator itr = childs.iterator();
while (itr.hasNext()) {
Element child = (Element)itr.next();
System.out.println(child.getText());
}
}
}