2011-02-07 114 views
2

有人能告诉我我需要运行一个.xml文件吗?我可以在记事本 中创建它并将其保存为.xml扩展名,然后在Windows中双击该文件或执行 我需要一个特殊的编辑器?xml - 如何创建/运行XML文件

我有一个java应用程序,并希望使用Jave Web Start技术,它需要我的.jar文件中的一个JNLP文件 。

感谢

+1

XML是文本 - 它不能在任何 “运行”。一个程序可以读取XML,解释它并对信息做些什么。 – Oded 2011-02-07 11:43:06

+1

你可以用记事本打开一个xml文件。或者更好的尝试[Notepad ++](http://notepad-plus-plus.org/)。为给定扩展名打开文件的默认应用程序(在这种情况下为.xml)可以更改为您选择的应用程序。 – 2011-02-07 11:43:36

+0

应该被标记为'混乱的想法'。请参阅@Oded:XML是数据,您不会运行数据。纯文本数据的方式,所以不需要特殊的编辑器(但一个体面的文本编辑器是非常有用的 - 为记事本+ + +1)。 – delnan 2011-02-07 11:44:55

回答

0

你不需要专门的编辑器,但可以有很大的帮助,同时编辑。

您无法运行xml文件。但是你可以运行一个使用xml文件的程序。

要“跑”的xml文件,你可能需要像下面的语句:

java -jar yourFile.jar packageOfMainMethod.ClassWithMainMethod yourXML.xml 

但是,这取决于你尝试运行该程序。

1

当然你可以运行一个xml文件。准确地说:你可以运行一个xsl文件,它是一种特殊的xml代码,但也可以像其他源代码一样运行纯文本。运行xslt脚本的解释器是您的浏览器。
所以你需要两个文件:

a。包含数据和脚本使用信息的xml文件(将其命名为“test.xml”):

<?xml version="1.0" encoding="utf-8"?> 
<?xml-stylesheet type="text/xsl" href="test.xsl"?> 
<root>data</root> 

b。包含脚本(其命名为“test.xsl”)的XSL文件:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/"> 
    <html> 
     <head> 
     <title>Show XML</title> 
     <head> 
     <body> 
     <xsl:value-of select="."/> 
     </body> 
    </html> 
    </xsl:template> 
</xsl:stylesheet> 

如果您的操作系统不知道在打开XML文件使用哪个程序,告诉他这是浏览器。 是的,你只需要像记事本和任何浏览器像firefox或ie任何编辑器。使用一个知道XML更方便,但记事本和即已经是一个完整的开发环境 - standanlone,不需要任何Java,所以我不知道你为什么提到它。

1

这是一个简单的插入到XML文件中使用C#

{ invoke方法第一..............

public void InvokeKey() 
    { 
     DSXml.ReadXml(@"c:\users\general\documents\visual studio 2010\Projects\xml_practice\xml_practice\todolist.xml"); 

     DataColumn[] ID = new DataColumn[1]; 

     ID[0] = DSXml.Tables[0].Columns[0]; 

     DSXml.Tables[0].PrimaryKey = ID; 
    } 

数据集DsXml =新的数据集(); DataRow DrXML;

string Date = Convert.ToString(System.DateTime.Now.ToString("d")); 
    string Time = Convert.ToString(System.DateTime.Now.ToString("hh:mm:ss")); 

    int ID; 




    InvokeKey(); 
      DRXML = DSXml.Tables[0].Rows.Find(ID); 

    DsXml.WriteXml(@"path"); 

     DrXML = DsXml.Tables[0].NewRow(); 

     DrXML[0] = ID; 
     DrXML[0] = ID; 
     DrXML[0] = ID; 
     DrXML[0] = ID; 
     DrXML[0] = ID; 
     DrXML[0] = ID; 

     DsXml.Tables[0].Rows.Add(DrXML); 

     DsXml.WriteXml(@"path"); 

dt = REport.LoadSubjects();

 Excel.Application xlApp = new Excel.Application(); // open app 
     xlApp.Visible = true; 

     Excel.Workbook xlWorkBook = xlApp.Workbooks.Add(1); //open workbook 
     Excel.Worksheet xlSheet = (Excel.Worksheet)xlWorkBook.Worksheets[1]; //open worksheet 


     xlSheet.Cells.Rows.Columns.AutoFit(); 

     string strTempVariable = dt.Rows[0][0].ToString(); //temporary variable 

     xlSheet.Cells[4, 1] = dt.Rows[0][0].ToString(); 

     xlSheet.Cells[1, 1] = "Employees group header"; 

     for (int count = 0; count < dt.Columns.Count;count++) 
     { 
      xlSheet.Cells[3, count+1] = dt.Columns[count].ColumnName;// prints column names 
     } 
     int group=0; 
     int total=0; 
     int intRow = 5;//manages xlsheet 

     for (int counter = 0; counter < dt.Rows.Count;counter++) 
     { 
      if (strTempVariable == dt.Rows[counter]["City"].ToString()) 
      { 
       xlSheet.Cells[intRow, 2] = dt.Rows[counter][1]; 
       xlSheet.Cells[intRow, 3] = dt.Rows[counter][2]; 
       xlSheet.Cells[intRow, 4] = dt.Rows[counter][3]; 
       xlSheet.Cells[intRow, 5] = dt.Rows[counter][4]; 
       group++; 
       total++; 
       intRow++; 
      } 
      else 
      { 
       xlSheet.Cells[intRow, 4] = "group name " + strTempVariable + " " + group.ToString(); 

       strTempVariable = dt.Rows[counter][0].ToString(); 
       intRow++; 
       xlSheet.Cells[intRow, 1] = strTempVariable; 
       intRow++; 
       counter--; 
       group = 0; 
      } 

     } 
      intRow++; 
     xlSheet.Cells[intRow, 4] = "group name " + strTempVariable + " "+group.ToString(); 
      intRow++; 
     xlSheet.Cells[intRow, 4] = "GrandTotal " + " "+total.ToString(); 



     xlWorkBook.Close(true, "GROUP REPORT", 0);//The name of the worksheet 

     xlApp.Quit(); 

     // return "Report Successfully"; 

    } 

公共字符串ReportTimeTable(){

 DataTier.clsDataAccess Data = new DataTier.clsDataAccess(); 

     int intCount = 0; 
     int intCount2 = 5; 


     Data.sqlcon.Close(); 
     Data.sqlcon.Open(); 


     Data.sqlAdpter = new SqlDataAdapter("SELECT * FROM USERS ORDER BY password",Data.sqlcon); 
     DataTable ReportDt = new DataTable("Report"); 

     Data.sqlAdpter.Fill(ReportDt); 
     Data.sqlcon.Close(); 

     string strMsg = ""; 

     Excel.Application xlApp = new Excel.Application(); 
     xlApp.Visible = true; 



     Excel.Workbook xlWorkbook = xlApp.Workbooks.Add(1); 
     Excel.Worksheet xlWorksheet = (Excel.Worksheet)xlWorkbook.Sheets[1]; 


     // Setting cell values 
     ((Excel.Range)xlWorksheet.Cells[1, "A"]).Value2 = "Report - USERS "; //main heading 

     ((Excel.Range)xlWorksheet.Cells[3, "A"]).Value2 = "USERNAME"; //field headings 
     ((Excel.Range)xlWorksheet.Cells[3, "B"]).Value2 = "PASSWORD"; 
     // ((Excel.Range)xlWorksheet.Cells[3, "C"]).Value2 = "MARK"; 


     for (intCount = 0; intCount < ReportDt.Rows.Count; intCount++) 
     { 
      xlWorksheet.Cells[intCount2, "A"] = ReportDt.Rows[intCount][0]; 
      xlWorksheet.Cells[intCount2, "B"] = ReportDt.Rows[intCount][1]; 
      // xlWorksheet.Cells[intCount2, "C"] = ReportDt.Rows[intCount][2]; 


      intCount2++; 
     } 
     xlWorksheet.Cells.Columns.AutoFit(); 
     strMsg = "report successful"; 
     return strMsg;