本文整理汇总了C#中System.Xml.XmlDocument.InsertBefore方法的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.XmlDocument.InsertBefore方法的具体用法?C# System.Xml.XmlDocument.InsertBefore怎么用?C# System.Xml.XmlDocument.InsertBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了System.Xml.XmlDocument.InsertBefore方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveTo
public static void SaveTo(string path)
{
path = System.IO.Path.GetFullPath(path);
FullPath = path;
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
var element = Data.IO.SaveObjectToElement(doc, "Root", Core.Root, false);
var behaviorElement = Data.IO.SaveObjectToElement(doc, "Behavior", EffectBehavior, false);
var cullingElement = Data.IO.SaveObjectToElement(doc, "Culling", Culling, false);
System.Xml.XmlElement project_root = doc.CreateElement("EffekseerProject");
project_root.AppendChild(element);
if(behaviorElement != null) project_root.AppendChild(behaviorElement);
if (cullingElement != null) project_root.AppendChild(cullingElement);
project_root.AppendChild(doc.CreateTextElement("ToolVersion", Core.Version));
project_root.AppendChild(doc.CreateTextElement("Version", 3));
project_root.AppendChild(doc.CreateTextElement("StartFrame", StartFrame));
project_root.AppendChild(doc.CreateTextElement("EndFrame", EndFrame));
project_root.AppendChild(doc.CreateTextElement("IsLoop", IsLoop.ToString()));
doc.AppendChild(project_root);
var dec = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.InsertBefore(dec, project_root);
doc.Save(path);
IsChanged = false;
if (OnAfterSave != null)
{
OnAfterSave(null, null);
}
}
示例2: SaveConfig
internal static void SaveConfig()
{
{
var rf = GetRecentFiles();
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
System.Xml.XmlElement project_root = doc.CreateElement("Recent");
foreach (var f in rf.Reverse())
{
project_root.AppendChild(doc.CreateTextElement("File", f));
}
doc.AppendChild(project_root);
var dec = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.InsertBefore(dec, project_root);
doc.Save(configRecentPath);
}
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
System.Xml.XmlElement project_root = doc.CreateElement("GUI");
if (MainForm.WindowState == FormWindowState.Normal)
{
project_root.AppendChild(doc.CreateTextElement("X", MainForm.Location.X.ToString()));
project_root.AppendChild(doc.CreateTextElement("Y", MainForm.Location.Y.ToString()));
project_root.AppendChild(doc.CreateTextElement("Width", MainForm.Width.ToString()));
project_root.AppendChild(doc.CreateTextElement("Height", MainForm.Height.ToString()));
}
else // 最小化、最大化中はその前の位置とサイズを保存
{
project_root.AppendChild(doc.CreateTextElement("X", MainForm.BeforeResizeLocation.X.ToString()));
project_root.AppendChild(doc.CreateTextElement("Y", MainForm.BeforeResizeLocation.Y.ToString()));
project_root.AppendChild(doc.CreateTextElement("Width", MainForm.BeforeResizeWidth.ToString()));
project_root.AppendChild(doc.CreateTextElement("Height", MainForm.BeforeResizeHeight.ToString()));
}
doc.AppendChild(project_root);
var dec = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.InsertBefore(dec, project_root);
doc.Save(configGuiPath);
}
MainForm.Panel.SaveAsXml(configGuiPanelPath, Encoding.UTF8);
Network.Save(configNetworkPath);
}
示例3: SaveOption
public static void SaveOption()
{
var path = System.IO.Path.Combine(GetEntryDirectory(), OptionFilePath);
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
var optionElement = Data.IO.SaveObjectToElement(doc, "Option", Option, false);
System.Xml.XmlElement project_root = doc.CreateElement("EffekseerProject");
if(optionElement != null) project_root.AppendChild(optionElement);
doc.AppendChild(project_root);
var dec = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.InsertBefore(dec, project_root);
doc.Save(path);
IsChanged = false;
}
示例4: CheckAndFixXMLInput
void CheckAndFixXMLInput(string Filename)
{
System.Xml.XmlDocument xmld = new System.Xml.XmlDocument();
xmld.Load(Filename);
if (xmld.FirstChild.NodeType != System.Xml.XmlNodeType.XmlDeclaration)
{
System.Xml.XmlAttribute atr;
System.Xml.XmlNode node;
DateTime dt;
atr = xmld.CreateAttribute("xmlns:xsd");
atr.Value = "http://www.w3.org/2001/XMLSchema";
xmld.FirstChild.Attributes.Append(atr);
atr = xmld.CreateAttribute("xmlns:xsi");
atr.Value = "http://www.w3.org/2001/XMLSchema-instance" ;
xmld.FirstChild.Attributes.Append(atr);
atr = xmld.CreateAttribute("xmlns");
atr.Value = "http://carverlab.com/xsd/VideoExchange.xsd";
xmld.FirstChild.Attributes.Append(atr);
xmld.InsertBefore(xmld.CreateXmlDeclaration("1.0","utf-8",""),xmld.FirstChild);
node = xmld.SelectSingleNode("CARDVIDEO/TIMESTART");
dt = DateTime.Parse(node.InnerText);
node.InnerText = dt.ToString("s",System.Globalization.DateTimeFormatInfo.InvariantInfo);
node = xmld.SelectSingleNode("CARDVIDEO/TIMESTOP");
dt = DateTime.Parse(node.InnerText);
node.InnerText = dt.ToString("s",System.Globalization.DateTimeFormatInfo.InvariantInfo);
xmld.Save(Filename);
}
}
示例5: SaveXmlDefaultConfigurationFile
/// <summary>
/// Create and Save a default configuration Xml file based on a easily specific or default defined xml string
/// </summary>
/// <param name="FilePath">The fullpath including filename.xml to save to</param>
/// <param name="XmlConfigurationFileString">If not specified, then will use the XmlDefaultConfigurationFileString</param>
/// <returns>True if succesfull created</returns>
/// <remarks></remarks>
public bool SaveXmlDefaultConfigurationFile(string FilePath, string XmlConfigurationFileString)
{
string theXmlString = ((XmlConfigurationFileString != null) ? XmlConfigurationFileString : XmlDefaultConfigurationFileString);
//What Method You want to use ?, try any by simply change the var XmlSaveMethod declared at top
switch (XmlSaveMethod) {
case enumXmlSaveMethod.StreamWrite:
//Easy Method
using (System.IO.StreamWriter StreamWriter = new System.IO.StreamWriter(FilePath)) {
//Without Compact Framework more easily using file.WriteAllText but, CF doesn't have this method
StreamWriter.Write(theXmlString);
StreamWriter.Close();
}
return true;
case enumXmlSaveMethod.XmlTextWriter:
//Alternative Method
using (System.Xml.XmlTextWriter XmlTextWriter = new System.Xml.XmlTextWriter(FilePath, System.Text.UTF8Encoding.UTF8)) {
XmlTextWriter.WriteStartDocument();
XmlTextWriter.WriteStartElement("configuration");
XmlTextWriter.WriteStartElement("appSettings");
foreach (string Item in GetListItems(theXmlString)) {
XmlTextWriter.WriteStartElement("add");
XmlTextWriter.WriteStartAttribute("key", string.Empty);
XmlTextWriter.WriteRaw(GetKey(Item));
XmlTextWriter.WriteEndAttribute();
XmlTextWriter.WriteStartAttribute("value", string.Empty);
XmlTextWriter.WriteRaw(GetValue(Item));
XmlTextWriter.WriteEndAttribute();
XmlTextWriter.WriteEndElement();
}
XmlTextWriter.WriteEndElement();
XmlTextWriter.WriteEndElement();
//XmlTextWriter.WriteEndDocument()
XmlTextWriter.Close();
}
return true;
case enumXmlSaveMethod.XmlDocument:
//Method you will practice
System.Xml.XmlDocument XmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement xRoot = XmlDoc.CreateElement("configuration");
XmlDoc.AppendChild(xRoot);
System.Xml.XmlElement xAppSettingsElement = XmlDoc.CreateElement("appSettings");
xRoot.AppendChild(xAppSettingsElement);
System.Xml.XmlElement xElement = default(System.Xml.XmlElement);
System.Xml.XmlAttribute xAttrKey = default(System.Xml.XmlAttribute);
System.Xml.XmlAttribute xAttrValue = default(System.Xml.XmlAttribute);
foreach (string Item in GetListItems(theXmlString)) {
xElement = XmlDoc.CreateElement("add");
xAttrKey = XmlDoc.CreateAttribute("key");
xAttrValue = XmlDoc.CreateAttribute("value");
xAttrKey.InnerText = GetKey(Item);
xElement.SetAttributeNode(xAttrKey);
xAttrValue.InnerText = GetValue(Item);
xElement.SetAttributeNode(xAttrValue);
xAppSettingsElement.AppendChild(xElement);
}
System.Xml.XmlProcessingInstruction XmlPI = XmlDoc.CreateProcessingInstruction("xml", "version='1.0' encoding='utf-8'");
XmlDoc.InsertBefore(XmlPI, XmlDoc.ChildNodes[0]);
XmlDoc.Save(FilePath);
return true;
}
return false;
}
示例6: SaveXmlCurrentConfiguration
public object SaveXmlCurrentConfiguration(string StrPath, string StrFilename /*= "AppSettings.xml"*/)
{
//Conform the Path
string FilePath = (!(StrPath == null) ? StrPath : System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)) + "\\" + StrFilename;
System.Xml.XmlDocument XmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement xRoot = XmlDoc.CreateElement("configuration");
XmlDoc.AppendChild(xRoot);
System.Xml.XmlElement xAppSettingsElement = XmlDoc.CreateElement("appSettings");
xRoot.AppendChild(xAppSettingsElement);
System.Xml.XmlElement xElement = default(System.Xml.XmlElement);
System.Xml.XmlAttribute xAttrKey = default(System.Xml.XmlAttribute);
System.Xml.XmlAttribute xAttrValue = default(System.Xml.XmlAttribute);
//For Each Item As String In Me.ListItems
for (int i = 0; i <= this.ListItems.Count - 1; i++) {
xElement = XmlDoc.CreateElement("add");
xAttrKey = XmlDoc.CreateAttribute("key");
xAttrValue = XmlDoc.CreateAttribute("value");
xAttrKey.InnerText = this.ListItems.GetKey(i);
xElement.SetAttributeNode(xAttrKey);
xAttrValue.InnerText = this.ListItems[i];
xElement.SetAttributeNode(xAttrValue);
xAppSettingsElement.AppendChild(xElement);
}
System.Xml.XmlProcessingInstruction XmlPI = XmlDoc.CreateProcessingInstruction("xml", "version='1.0' encoding='utf-8'");
XmlDoc.InsertBefore(XmlPI, XmlDoc.ChildNodes[0]);
XmlDoc.Save(FilePath);
return true;
}
示例7: Read
public void Read(string Filename)
{
// now load this bugger up and get rid or all the junk that WMP can't parse
System.Xml.XmlDocument xmld = new System.Xml.XmlDocument();
xmld.Load(Filename);
System.Xml.XmlDeclaration xmldecl = xmld.CreateXmlDeclaration("1.0",null,null);
xmld.InsertBefore(xmldecl,xmld.DocumentElement);
string TempFile = System.IO.Path.GetTempFileName();
xmld.Save(TempFile);
System.IO.TextReader tw = System.IO.File.OpenText(TempFile);
m_asx = (CarverLab.Utility.ASX)base.Deserialize(tw);
tw.Close();
System.IO.File.Delete(TempFile);
}