例如XML信息如下:
<?xml version="1.0"?>
<book>
<contents>
<chapter title="Introduction" number="1">
<topic name="XML Matters"/>
<topic name="What's Important"/>
<topic name="The Essentials"/>
<topic name="What's Next?"/>
</chapter>
<chapter title="Nuts and Bolts" number="2">
<topic name="The Basics"/>
<topic name="Constraints"/>
<topic name="Transformations"/>
<topic name="And More..."/>
<topic name="What's Next?"/>
</chapter>
</contents>
</book>1.求将上面的XML发送到本机一个JSP或Servlet的代码,如JSP文件名为jsp1.jsp,SERVLET名为servlet1
2.在JSP或SERVLET中接收并解析,最好用DOM的方式,在线等,立即结贴.
<?xml version="1.0"?>
<book>
<contents>
<chapter title="Introduction" number="1">
<topic name="XML Matters"/>
<topic name="What's Important"/>
<topic name="The Essentials"/>
<topic name="What's Next?"/>
</chapter>
<chapter title="Nuts and Bolts" number="2">
<topic name="The Basics"/>
<topic name="Constraints"/>
<topic name="Transformations"/>
<topic name="And More..."/>
<topic name="What's Next?"/>
</chapter>
</contents>
</book>1.求将上面的XML发送到本机一个JSP或Servlet的代码,如JSP文件名为jsp1.jsp,SERVLET名为servlet1
2.在JSP或SERVLET中接收并解析,最好用DOM的方式,在线等,立即结贴.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
doc= builder.parse(f);
Element root = doc.getDocumentElement();
path 是文件路径
你获取root就可以对XML操作啦,