Import java. Lang. String;
Import java. RMI. RemoteException;
Import java. util. iterator;
Import java. util. List;
Import org. Apache. axis2.axisfault;
Import org. dom4j .*;
Public class user
{
// Convert an XML string into an HTML language in the form of a table
Public static string outputintable (string XML, string trclass, string tdclass)
{
// Html of the output result
String table = "";
// Output the HTML of the table Header
String tablehead = "";
Try
{
// Read string-type XML and convert it to document
Document Doc = incluenthelper. parsetext (XML );
// Get the XML Root Node
// Element root = Doc. getrootelement ();
// Obtain the list of child nodes of the root element
// System. Out. println (DOM. getnode (Doc, "/dataset/table/ID"). gettext ());
// Obtain the location of all tables
List L = Doc. selectnodes ("/dataset/table ");
Iterator headiter = L. iterator ();
Iterator contentiter = L. iterator ();
// Retrieve the header part: retrieve all column headers from the first table
Element headtmp = (element) headiter. Next ();
List headtd = headtmp. Elements ();
Iterator headtditer = headtd. iterator ();
Tablehead = "<TR" + "class =" + trclass + "> ";
// Store the names of all elements in the first table to tablehead.
While (headtditer. hasnext ())
{
Element headtmpp = (element) headtditer. Next ();
Tablehead + = "<TD" + "class =" + tdclass + ">" + headtmpp. getname () + "</TD> ";
// System. Out. println (TMP. asxml () + "/N ");
}
Tablehead + = "</tr> ";
// Use the data in XML as the data in the table
// Obtain the element values cyclically in each table
While (contentiter. hasnext ())
{
Element TMP = (element) contentiter. Next ();
List TD = TMP. Elements ();
Iterator tditer = TD. iterator ();
Table + = "<TR" + "class =" + trclass + "> ";
// Obtain the values of each element in the table
While (tditer. hasnext ())
{
Element tmpp = (element) tditer. Next ();
Table + = "<TD" + "class =" + tdclass + ">" + tmpp. gettext () + "</TD> ";
}
// System. Out. println (TMP. asxml () + "/N ");
Table + = "</tr>/N ";
}
Table = tablehead + "/N" + table;
}
Catch (incluentexception E)
{
E. printstacktrace ();
}
Return table;
}
Public static void main (string [] ARGs)
{
String xml = "<dataset> <Table> <ID> 1 </ID> <serviceid> 0 </serviceid> <servicename> basic </servicename> <memo> basic </ memo> </table> <Table> <ID> 2 </ID> <serviceid> 1 </serviceid> <servicename> SMS </servicename> <memo> SMS notification </ memo> </table> <Table> <ID> 3 </ID> <serviceid> 2 </serviceid> <servicename> VoIP </servicename> <memo> VoIP </memo> </table> <Table> <ID> 4 </ID> <serviceid> 3 </serviceid> <servicename> diskspace </servicename> <memo> large disk space </ memo> </table> </dataset> ";
System. Out. println (user. outputintable (XML, "trclass", "tdclass "));
}
}