2011-02-07 169 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;