js|xml| interaction
Saxpser.parse (XmlFile, handler);
After parsing, use the Handler.gettable () method to return a hash table with data saved
Hashtable hshtable = handler.gettable ();
FILE://uses the collection enumeration to get all the key values in the hash table hshtable
Enumeration Enum=hshtable.keys ();
Object obj;
while (Enum.hasmoreelements ()) {
file://the next element object in the collection
Obj=enum.nextelement ();
Output to JSP page via JSP's built-in object out
The File://hshTable.get () method is used to get the corresponding value based on the key obj.
Out.println ("
"+obj+" = = "+ (String) hshtable.get (obj));
}
}
catch (Saxexception e) {
file://If there is an error, print error details
E.printstacktrace ();
}
%>
The code is well written, put this file in the Web application directory, and then run the program through the browser, such as http://192.168.0.98:7070/welcome_html/jspxml.jsp?file=e:\\ Personal.xml, note that you must use parameters? file= path \\personal.xml (the path is based on the directory you save on your hard disk, Java says: "\ \" is a "\" on the Windows system), and the effect is as follows:
As you can see, all the data in the XML file is read through this JSP file, because the JSP program is file-independent, you can also change the XML file name in File=e:\\personal.xml to other XML files to see the last run effect.
To illustrate the point is that I actually adopted the JAXP1.01 version of the API, there may be my system reasons, the Discovery program in version 1.1 can be compiled, but the runtime will be the following error (even if the JAXP1.1 package with the example of the Main.java also):
Java.lang.NoClassDefFoundError:org.apache.crimson.jaxp.SAXParserFactoryImpl
So finally the 1.01 version of JAXP is used to run the program, and the 1.01 version of JAXP can also be downloaded at the address above.
< personal files >
< name > Liu Yufeng
< sex > Male
< age >24
Coolknight@263.net
< personal homepage >http://www.21jsp.com
< introduction > Welcome to visit my homepage!