有这样一个xml文件,怎么把它的内容以表格的形式显示在页面上啊?请各位帮帮忙拉?小妹是在不会啊?
<?xml version="1.0" encoding="UTF-8" ?> 
- <Bug--Info>
- <Bug>
  <kingdom>Encapsulation</kingdom> 
  <type>Poor Logging Practice</type> 
  <subtype>Use of a System Output Stream</subtype> 
  <defaultSeverity>2.0</defaultSeverity> 
  <beginstar>Class1.cs:38:38</beginstar> 
  <beginstardemo>adapter.Fill(oDataSet, "Contents"); //Print the records in XML format Console.WriteLine(oDataSet.GetXml()); ///Console.WriteLine(oDataSet.GetXml());/// ///Console.WriteLine(oDataSet.GetXml());/// ///Console.WriteLine(oDataSet.GetXml());///</beginstardemo> 
  <endstar>Class1.cs:38:38</endstar> 
  <endstardemo>adapter.Fill(oDataSet, "Contents"); //Print the records in XML format Console.WriteLine(oDataSet.GetXml()); ///Console.WriteLine(oDataSet.GetXml());/// ///Console.WriteLine(oDataSet.GetXml());/// ///Console.WriteLine(oDataSet.GetXml());///</endstardemo> 
  </Bug>
- <Bug>
  <kingdom>Input Validation and Representation</kingdom> 
  <type>SQL Injection</type> 
  <subtype /> 
  <defaultSeverity>4.0</defaultSeverity> 
  <endstar>Class1.cs:31:31</endstar> 
  <endstardemo>//Create an adapter object with a directly tainted string SqlDataAdapter adapter1 = new SqlDataAdapter(args[1], connectionstring); //Create an adapter object with a string contructed froma tainted sub-string SqlDataAdapter adapter2 = new SqlDataAdapter(tainted_query, connectionstring); //Create a dataset object and fill the values from Employees table DataSet oDataSet = new DataSet();</endstardemo> 
  <beginstar>Class1.cs:16:16</beginstar> 
  <beginstardemo>/// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { //Set the connection string for the database string connectionstring="Initial Catalog=TestCatalog; Data Source=myDataSource;user id=admin;password=adminadmin;";</beginstardemo> 
  </Bug>

解决方案 »

  1.   

    首先,你这个xml文件有不该有的代码 ////summary> [STAThread] static void Main(string[] args) { //Set the connection string for the database string.....也许你认为这是注释,你这代码语法都有错误,你让大家怎么帮你改?? 
      

  2.   


    try {
    Document doc = new Document();
    SAXBuilder sb = new SAXBuilder(false);
    doc = sb.build(new java.io.ByteArrayInputStream(xml
    .getBytes("utf-8")));
    Element bugElement = doc.getRootElement();
    List list = bugElement.getChildren("Bug"); for (int i = 0; i < list.size(); i++) {
    Element e = (Element) list.get(i);
    System.out.println(e.getChildText("kingdom"));
    System.out.println(e.getChildText("type"));
    System.out.println(e.getChildText("subtype"));
    System.out.println(e.getChildText("defaultSeverity"));
    System.out.println(e.getChildText("beginstar"));
    System.out.println(e.getChildText("beginstardemo"));
    System.out.println(e.getChildText("endstar"));
    System.out.println(e.getChildText("endstardemo"));
    }
    } catch (Exception e) {
    e.printStackTrace();
    }