本文整理汇总了C#中XmlDocument.Save方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.Save方法的具体用法?C# XmlDocument.Save怎么用?C# XmlDocument.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveStatistik
public void SaveStatistik(string statText, string name)
{
CheckFile ();
// Создаем корневой элемент
XmlDocument xmlDoc = new XmlDocument ();
if(File.Exists(filePatch))
xmlDoc.Load (filePatch);
XmlNode xRoot;
XmlNode findNode = xmlDoc.SelectSingleNode ("Stats"); // найти корневой элемент
if ( findNode == null)
xRoot = xmlDoc.CreateElement ("Stats"); // Создать корневой элемент
else
xRoot = findNode;
xmlDoc.AppendChild (xRoot);
//Временные преременные для дочерних элементов и атрибутов
XmlElement taskElement1; //Элемент 1-го уровня
findNode = xmlDoc.SelectSingleNode ("Stats/" + name);
if ( findNode == null) {
taskElement1 = xmlDoc.CreateElement (name);
taskElement1.InnerText = statText;
xRoot.AppendChild (taskElement1);
} else {
findNode.InnerText = statText;
}
/////////////////////////////////////////////////////////////
xmlDoc.Save ("Data/Save/Stats.xml");
}
示例2: Button1_ServerClick
protected void Button1_ServerClick(object sender, EventArgs e)
{
try
{
string currency = idChoice.Value;
XmlDocument doc = new XmlDocument();
string url = Server.MapPath("../data/xml/configproduct.xml");
XmlTextReader reader = new XmlTextReader(url);
doc.Load(reader);
reader.Close();
if (doc.IsReadOnly)
{
diverr.Visible = true;
diverr.InnerHtml = "File XML đã bị khóa. Không thể thay đổi";
return;
}
XmlNode nodeEdit = doc.SelectSingleNode("root/product[nameappunit='currency']/unit");
string value = nodeEdit.InnerText;
if (!value.Equals(currency))
{
nodeEdit.InnerText = currency;
doc.Save(url);
Application["currency"] = currency;
diverr.Visible = true;
diverr.InnerHtml = "Đã thay đổi cách hiển thị tiền tệ";
}
else
{
diverr.Visible = true;
diverr.InnerHtml = "Hệ thống đang hiển thị kiểu tiền này.";
}
}catch
{}
}
示例3: Main
//Using the DOM parser write a program to delete from catalog.xml
//all albums having price > 20.
static void Main()
{
XmlDocument doc = new XmlDocument();
string fileLocation = @"..\..\catalogue.xml";
doc.Load(fileLocation);
Console.WriteLine("Document Loaded");
XmlNode rootNode = doc.DocumentElement;
var count = rootNode.ChildNodes.Count;
for (int i = 0; i < count; i++)
{
XmlNode album = rootNode.ChildNodes[i];
XmlNode albumNode = album.FirstChild;
while (albumNode != null)
{
XmlNode nextSibling = albumNode.NextSibling;
double price = double.Parse(albumNode["Price"].InnerText);
if (price > 20)
{
album.RemoveChild(albumNode);
}
albumNode = nextSibling;
}
}
doc.Save(fileLocation);
}
示例4: RunFileAction
private static bool RunFileAction (XmlNode fileElement)
{
string path = GetAttribute (fileElement, "Path");
XmlDocument doc = new XmlDocument ();
try {
doc.Load (path);
} catch {
Console.WriteLine ("ERROR: Could not open {0}.", path);
return false;
}
Console.WriteLine ("Processing {0}...", path);
foreach (XmlNode element in fileElement.SelectNodes ("Replace"))
if (!ReplaceNode (fileElement.OwnerDocument, doc, element))
return false;
foreach (XmlNode element in fileElement.SelectNodes ("Insert"))
if (!InsertNode (fileElement.OwnerDocument, doc, element))
return false;
foreach (XmlNode element in fileElement.SelectNodes ("Remove"))
if (!RemoveNodes (doc, element))
return false;
doc.Save (path);
Console.WriteLine ("{0} saved.", path);
return true;
}
示例5: btnSave_Click
protected void btnSave_Click(object sender, EventArgs e)
{
if (tbxStart.Text == "" || tbxEnd.Text == "" || DateTime.Parse(tbxStart.Text) > DateTime.Parse(tbxEnd.Text))
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "s", "alert('时间选择不正确')", true);
return;
}
//保存活动有限期限到配置文件
string config = Server.MapPath("/config/app.config");
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(config);
XmlNodeList topM = xmldoc.DocumentElement.ChildNodes;
foreach (XmlElement element in topM)
{
if (element.Attributes["key"].Value == "quzhouDate")
{
element.Attributes["value"].Value = tbxStart.Text.Trim()+","+tbxEnd.Text.Trim();
}
}
xmldoc.Save(config);
string[] ticketId = ConfigurationManager.AppSettings["ticketId"].Split(',');
List<Ticket> listTicket = new List<Ticket>();
for (int i = 0; i < ticketId.Length; i++)
{
listTicket.Add(bllTicket.GetTicket(int.Parse(ticketId[i])));
}
bllta.SaveDate(DateTime.Parse(tbxStart.Text), DateTime.Parse(tbxEnd.Text), listTicket);
BindData();
ScriptManager.RegisterStartupScript(this, this.GetType(), "s", "alert('保存成功')", true);
}
示例6: EncryptFile
public static void EncryptFile(string path)
{
if (!File.Exists(path))
{
Debug.Log("File Not Found At: " + path);
return;
}
XmlDocument xmlFile = new XmlDocument();
xmlFile.Load(path);
XmlElement xmlRoot = xmlFile.DocumentElement;
if (xmlRoot.ChildNodes.Count > 1)
{
byte[] keyArray = UTF8Encoding.UTF8.GetBytes ("86759426197648123460789546213421");
byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes (xmlRoot.InnerXml);
RijndaelManaged rDel = new RijndaelManaged();
rDel.Key = keyArray;
rDel.Mode = CipherMode.ECB;
rDel.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = rDel.CreateEncryptor();
byte[] resultArray = cTransform.TransformFinalBlock (toEncryptArray, 0, toEncryptArray.Length);
xmlRoot.InnerXml = Convert.ToBase64String (resultArray, 0, resultArray.Length);
}
xmlFile.Save(path);
}
示例7: Main
static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("../../../catalog.xml");
XmlNode rootNode = doc.DocumentElement;
List<XmlNode> albumsForDeleting = new List<XmlNode>();
foreach (XmlNode node in rootNode.ChildNodes)
{
int price = int.Parse(node["price"].InnerText);
if (price > 20)
{
albumsForDeleting.Add(node);
}
}
foreach (var album in albumsForDeleting)
{
doc.DocumentElement.RemoveChild(album);
}
doc.Save("../../newCatalog.xml");
//For save the changes to the same file
//doc.Save("../../catalog.xml");
}
示例8: Main
static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load(@"..\..\..\catalogue.xml");
XmlNode rootNode = doc.DocumentElement;
for (int i = 0; i < rootNode.ChildNodes.Count; i++)
{
XmlNode node = rootNode.ChildNodes[i];
foreach (XmlNode albumPrice in node.ChildNodes)
{
// if the node is the price node
if (albumPrice.Name == "price")
{
// take the price
double price = double.Parse(albumPrice.InnerText);
if (price > 20.00)
{
rootNode.RemoveChild(node); // remove the node
i--; // decrementing i so that we won't miss a node
}
}
}
}
doc.Save(@"..\..\..\catalogueUnderTwentyPrice.xml");
}
示例9: Main
static void Main()
{
XmlDocument document = new XmlDocument();
document.Load(filePath);
XmlNode rootNode = document.DocumentElement;
var nodesToRemove = new List<XmlNode>();
foreach (XmlNode node in rootNode.ChildNodes)
{
decimal price = decimal.Parse(node["price"].InnerText, System.Globalization.NumberStyles.Currency, culture);
if (price > 20)
{
nodesToRemove.Add(node);
}
}
foreach (var node in nodesToRemove)
{
rootNode.RemoveChild(node);
}
document.Save(filePath);
}
示例10: Module_Action_Delete
private string Module_Action_Delete()
{
string tmpstr = "";
string trootstr = cls.getSafeString(encode.base64.decodeBase64(request.querystring("root")));
string tvaluestr = cls.getSafeString(encode.base64.decodeBase64(request.querystring("value")));
if (com.fileExists(Server.MapPath(trootstr)))
{
try
{
string tnode, tfield, tbase;
XmlDocument tXMLDom = new XmlDocument();
tXMLDom.Load(Server.MapPath(trootstr));
XmlNode tXmlNode = tXMLDom.SelectSingleNode("/xml/configure");
tnode = tXmlNode.ChildNodes.Item(0).InnerText;
tfield = tXmlNode.ChildNodes.Item(1).InnerText;
tbase = tXmlNode.ChildNodes.Item(2).InnerText;
XmlNode tXmlNodeDel = tXMLDom.SelectSingleNode("/xml/" + tbase + "/" + tnode + "[" + cls.getLRStr(tfield, ",", "left") + "='" + tvaluestr + "']");
if (tXmlNodeDel != null)
{
tXmlNodeDel.ParentNode.RemoveChild(tXmlNodeDel);
tXMLDom.Save(Server.MapPath(trootstr));
}
tmpstr = jt.itake("global.lng_common.delete-succeed", "lng");
}
catch
{
tmpstr = jt.itake("global.lng_common.delete-failed", "lng");
}
}
else tmpstr = jt.itake("global.lng_common.delete-failed", "lng");
tmpstr = config.ajaxPreContent + tmpstr;
return tmpstr;
}
示例11: SaveDataForCurrentUser
public static void SaveDataForCurrentUser()
{
try
{
string currentUser = TransitionData.GetUsername();
_document = new XmlDocument();
XmlElement completedLevels = _document.CreateElement(COMPLETED_LEVELS_NODE_NAME);
foreach (string answer in _completedLevels)
{
XmlElement completedLevelNode = _document.CreateElement(answer);
completedLevels.AppendChild(completedLevelNode);
}
_document.AppendChild(completedLevels);
_document.Save(GetSaveDataPathForUser(currentUser));
}
catch(Exception e)
{
Debug.LogError(e);
}
}
示例12: Main
static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("../../items.xml");
string culture = doc.DocumentElement.Attributes["culture"].Value;
CultureInfo numberFormat = new CultureInfo(culture);
// Promotion: decrease twice the price of all beers
foreach (XmlNode node in doc.DocumentElement)
{
if (node.Attributes["type"].Value == "beer")
{
string currentPriceStr = node["price"].InnerText;
decimal currentPrice = Decimal.Parse(currentPriceStr, numberFormat);
decimal newPrice = currentPrice / 2;
node["price"].InnerText = newPrice.ToString(numberFormat);
}
}
Console.WriteLine("Modified XML document:");
Console.WriteLine(doc.OuterXml);
doc.Save("../../itemsNew.xml");
}
示例13: OpenAppXMLFile
public XmlDocument OpenAppXMLFile()
{
string App_Path = @ConfigurationManager.AppSettings["Data_Path"].ToString();
App_Path = App_Path + "Items.xml";
if (File.Exists(@App_Path))
{
try
{
xmldoc = new XmlDocument();
xmldoc.Load(@App_Path);
}
catch (Exception ex)
{
/// Do not currently understand how to terminate the ThreadStart in the event of a failure
GlobalClass.ErrorMessage = "Error in AppThreads(OpenAppFile): " + ex.Message;
}
}
else
{
xmldoc = new XmlDocument();
XmlNode iheader = xmldoc.CreateXmlDeclaration("1.0", "UTF-8", null);
xmldoc.AppendChild(iheader);
XmlElement root = xmldoc.CreateElement("dataroot");
xmldoc.InsertAfter(root, iheader);
xmldoc.Save(@App_Path);
}
return xmldoc;
}
示例14: Main
static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("../../catalogue.xml");
XmlNode rootNode = doc.DocumentElement;
HashSet<string> artistsSet = new HashSet<string>();
List<XmlNode> albumsToDelete = new List<XmlNode>();
decimal searchedPrice = 15;
foreach (XmlNode node in rootNode.ChildNodes)
{
decimal parsedPrice = decimal.Parse(node["price"].InnerText);
if (parsedPrice > searchedPrice)
{
albumsToDelete.Add(node);
}
}
foreach (var album in albumsToDelete)
{
rootNode.RemoveChild(album);
}
// see the created catalogue_new.xml file to see that files are deleted
doc.Save("../../catalogue_new.xml");
}
示例15: DeleteAttribute
/// <summary>
/// 删除XmlNode属性
/// 使用示列:
/// XmlHelper.DeleteAttribute(path, nodeName, "");
/// XmlHelper.DeleteAttribute(path, nodeName, attributeName,attributeValue);
/// </summary>
/// <param name="path">文件路径</param>
/// <param name="nodeName">节点名称</param>
/// <param name="attributeName">属性名称</param>
/// <returns>void</returns>
public static void DeleteAttribute(string path, string nodeName, string attributeName)
{
if (attributeName.Equals(""))
{
return;
}
try
{
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlElement element = doc.SelectSingleNode(nodeName) as XmlElement;
if (element == null)
{
throw new Exception("节点元素不存在!");
}
else
{
element.RemoveAttribute(attributeName);
doc.Save(path);
}
}
catch
{ }
}