本文整理汇总了C#中XmlHelper.WriteTo方法的典型用法代码示例。如果您正苦于以下问题:C# XmlHelper.WriteTo方法的具体用法?C# XmlHelper.WriteTo怎么用?C# XmlHelper.WriteTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlHelper
的用法示例。
在下文中一共展示了XmlHelper.WriteTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnDeploy_Click
private void btnDeploy_Click(object sender, EventArgs e)
{
err.Clear();
bool valid = true;
if (string.IsNullOrWhiteSpace(txtVersion.Text))
{
err.SetError(txtVersion, "版本不可空白");
valid = false;
}
Version version;
if (!Version.TryParse(txtVersion.Text, out version))
{
err.SetError(txtVersion, "無效的版本編號");
valid = false;
}
if (!valid) return;
string localPath = MainForm.CurrentProject.TryGetLocalPath();
string path = Path.Combine(localPath, "udm.xml");
string dirPath = Path.Combine(localPath, "udm");
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
string vs = version.ToString().Replace(".","_");
string filename = MainForm.CurrentProject.Name + "_v_" + vs + ".pml";
string udtfname = "UDT_" + vs + ".tcmd";
string targetFilename = Path.Combine(dirPath,filename);
string udtFileName = Path.Combine(dirPath, udtfname);
//string ufUrl = PathHelper.CombineURL(_fileNodeHandler.ModuleHandler.HttpURL, "udm", udtfname);
string ufUrl = PathHelper.CombineURL("udm", udtfname);
lblInfo.Text = "匯出 tcmd 檔 「" + filename + "」 中 .....";
Application.DoEvents();
this.GetCmdElement().OwnerDocument.Save(udtFileName);
lblInfo.Text = "匯出 PML 檔 「" + filename + "」 中 .....";
Application.DoEvents();
// 這是舊版寫法, 新版的要另外寫
//_projectNodeHandler.ExportPML(targetFilename);
#region 產生 PML 檔 (新版)
XmlHelper h = new XmlHelper("<Project/>");
h.SetAttribute(".", "Name", MainForm.CurrentProject.Name);
XmlElement udtElement = h.AddElement(".", "Property");
udtElement.SetAttribute("Name", "UDT");
if (rbExtend.Checked)
{
XmlDocument d = new XmlDocument();
try
{
string url = PathHelper.CombineURL(_fileNodeHandler.ModuleHandler.HttpURL, txtPreVerURL.Text);
//string path = Path.Combine(_fileNodeHandler.ModuleHandler.HttpURL, txtPreVerURL.Text);
d.Load(url);
}
catch (Exception ex)
{
err.SetError(txtPreVerURL, "載入失敗 : " + ex.Message);
return;
}
XmlHelper h1 = new XmlHelper(d.DocumentElement);
foreach (XmlElement preUDTElement in h1.GetElements("Property[@Name='UDT']/Release"))
{
h.AddElement("Property[@Name='UDT']",preUDTElement);
}
}
XmlElement ne = h.AddElement("Property[@Name='UDT']", "Release");
ne.SetAttribute("Version", version.ToString());
ne.SetAttribute("URL", ufUrl);
XmlElement udsElement = h.AddElement(".", "Property");
udsElement.SetAttribute("Name", "UDS");
XmlHelper udsHelper = new XmlHelper(udsElement);
foreach (ContractHandler contract in MainForm.CurrentUDS.Contracts)
{
udsHelper.AddElement(".", contract.GetXml());
}
h.WriteTo(targetFilename);
#endregion
lblInfo.Text = "產生 UDM 檔案中......";
Application.DoEvents();
h = new XmlHelper("<Module/>");
h.SetAttribute(".", "Name", MainForm.CurrentProject.Name);
h.SetAttribute(".", "Version", version.ToString());
h.SetAttribute(".", "Provider", txtProvider.Text);
XmlElement download = h.AddElement(".", "Release");
//string downloadURL = PathHelper.CombineURL(_fileNodeHandler.ModuleHandler.HttpURL, "udm", filename);
string downloadURL = PathHelper.CombineURL("udm", filename);
download.SetAttribute("URL", downloadURL);
//.........这里部分代码省略.........
示例2: Export
public void Export()
{
XmlElement e = ServiceDAL.GetRawService(this.ContractName, this.PackageName, this.ServiceName);
SaveFileDialog sd = new SaveFileDialog();
sd.DefaultExt = "xml";
sd.FileName = this.ServiceName + ".xml";
sd.Filter = "(*.xml)|*.xml";
DialogResult dr = sd.ShowDialog();
if (dr != DialogResult.OK) return;
string formated = XmlHelper.Format(e.OwnerDocument.OuterXml);
XmlHelper h = new XmlHelper(formated);
h.WriteTo(sd.FileName);
}