xml - 如何创建/运行 XML 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4920877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
xml - how to create/run XML file
提问by Kurt
Can someone advise me on what I need to run an .xml file? Can I create it in Notepad and save it with an .xml extension then double click the file whilst in Windows or do I need a special editor?
有人可以告诉我运行 .xml 文件需要什么吗?我可以在记事本中创建它并使用 .xml 扩展名保存它,然后在 Windows 中双击该文件还是我需要一个特殊的编辑器?
I have a java application and want to use Jave Web Start techonology which requires a JNLP file from my .jar file.
我有一个 Java 应用程序,想使用 Java Web Start 技术,它需要来自我的 .jar 文件的 JNLP 文件。
Thanks
谢谢
回答by Andreas
Of course you can run an xml file. To be exact: you can run an xsl file, which is a special kind of xml with xslt code, but also pure text just as other source code. The interpreter on which the xslt script runs is your browser.
So you need two files:
当然你可以运行一个xml文件。确切地说:您可以运行一个 xsl 文件,它是一种带有 xslt 代码的特殊 xml,但也可以像其他源代码一样是纯文本。运行 xslt 脚本的解释器是您的浏览器。
所以你需要两个文件:
a. An xml file containing the data and the information which script to use (name it "test.xml"):
一种。包含数据和要使用的脚本信息的 xml 文件(将其命名为“test.xml”):
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<root>data</root>
b. An xsl file containing the script (name it "test.xsl"):
湾 包含脚本的 xsl 文件(将其命名为“test.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>
If your OS doesn't know which program to use on opening the xml file, tell him it's the browser. And yes, you only need any editor like notepad and any browser like firefox or ie. Using one which knows xml is more convinient, but notepad and ie are already a complete development environment - standanlone, without needing any java, so I don't know why you mention it.
如果您的操作系统不知道在打开 xml 文件时使用哪个程序,请告诉他这是浏览器。是的,您只需要像记事本这样的任何编辑器和像 firefox 或 ie 这样的任何浏览器。使用知道xml的更方便,但是notepad和ie已经是一个完整的开发环境了——standanlone,不需要任何java,所以不知道你为什么提。
回答by user3062716
this is a simple Insert into an xml file using C#
这是使用 C# 简单插入到 xml 文件中
{ invoke method first..............
{先调用方法.......
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;
}
DataSet DsXml = new DataSet(); DataRow DrXML;
数据集 DsXml = 新数据集(); 数据行 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();
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";
}
public string ReportTimeTable() {
公共字符串 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;
回答by Thijs Wouters
You do not need a special editor, but that can help a lot while editing.
您不需要特殊的编辑器,但这在编辑时会很有帮助。
You cannot run an xml-file. But you can run a program which uses the xml-file.
您不能运行 xml 文件。但是你可以运行一个使用 xml 文件的程序。
To "run" the xml file, you probably need something like the following statement:
要“运行” xml 文件,您可能需要类似以下语句的内容:
java -jar yourFile.jar packageOfMainMethod.ClassWithMainMethod yourXML.xml
But this depends on the program you try to run.
但这取决于您尝试运行的程序。

