//请教大家下面是JAVA,本人想把XML 导入里面 package books; import org.w3c.dom.*; import javax.xml.parsers.*; import java.net.URI; import java.io.*; import java.applet.*;
public class BookDetails extends Applet{ public void init(){ Document doc=null; try{ DocumentBuilderFactory.newInstance(); DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db=dbf.newDocumentBuilder(); doc=db.parse(new File("b.xml")); String nm="http://www.123books.com/booktitles"; String local="a"; String ob="http://www.onlinebooks.com"; System.out.println(nm+"名字空间的元素"); NodeList nl=doc.getElementsByTagNameNS(nm,"*"); for(int i=0;i<nl.getLength();i++) { //System.out.println("第一个FOR"); Node n=nl.item(i); System.out.println(n.getNodeName()); } System.out.println("\n名称为"+ob+"中的属性/。。。"); nl=doc.getElementsByTagName("*"); for(int i=0;i<nl.getLength();i++) { if(nl.item(i)instanceof Element){ Text t=(Text)nl.item(i).getFirstChild(); Element e=(Element)nl.item(i); //System.out.println("第二个FOR"); Attr a=e.getAttributeNodeNS(ob,"class"); if(a!=null){ String val=a.getNodeValue(); System.out.println("<"+val+">"+t.getNodeValue()+"</"+val+">"); } } } } catch(Exception e) { System.out.println("异常"+e.getMessage()); e.printStackTrace(); } } } //下面是XML <?xml version="1.0" encoding="gb2312"?> <BookDetails> <book xmlns="http://www.123books.com/booktitles"> <title price="$69">《Java编程思想》</title> <chapter title="网络编程"> <author title="Mr." name="Bruce Eckel"/>
</chapter> </book>
<order xmlns:html="http://www.onlinebooks.com"> <name html:class="H1">斯科特.猥陋秘书</name> <payment type="credit" html:class="H3">已和就</payment> <html:a href="">/java/prejksaf</html:a> <data location="Atlanta" html:class="H3">2003,年3月21日</data> </order> </BookDetails> /下面是HTML <applet code="BookDetails"></applet> 但是编译不起来 请问错误在什么地方啊