本文整理汇总了C#中XmlDocument.InsertBefore方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.InsertBefore方法的具体用法?C# XmlDocument.InsertBefore怎么用?C# XmlDocument.InsertBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.InsertBefore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetXml
/// <summary>
/// To Create Xml file for every multiselect list to pass data of xml type in database
/// </summary>
/// <param name="DtXml"></param>
/// <param name="Text"></param>
/// <param name="Value"></param>
/// <param name="XmlFileName"></param>
/// <returns></returns>
public string GetXml(DataTable DtXml, String Text, String Value,string XmlFileName)
{
XmlDocument xmldoc = new XmlDocument();
//To create Xml declarartion in xml file
XmlDeclaration decl = xmldoc.CreateXmlDeclaration("1.0", "UTF-16", "");
xmldoc.InsertBefore(decl, xmldoc.DocumentElement);
XmlElement RootNode = xmldoc.CreateElement("Root");
xmldoc.AppendChild(RootNode);
for (int i = 0; i < DtXml.Rows.Count; i++)
{
XmlElement childNode = xmldoc.CreateElement("Row");
childNode.SetAttribute(Value, DtXml.Rows[i][1].ToString());
childNode.SetAttribute(Text, DtXml.Rows[i][0].ToString());
RootNode.AppendChild(childNode);
}
//Check if directory already exist or not otherwise
//create directory
if (!Directory.Exists(System.Web.HttpContext.Current.Server.MapPath("XML")))
Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath("XML"));
XmlFileName = "XML" + "\\" + XmlFileName;
//To save xml file on respective path
xmldoc.Save(System.Web.HttpContext.Current.Server.MapPath(XmlFileName));
xmldoc.RemoveChild(xmldoc.FirstChild);
string RetXml = xmldoc.InnerXml;
return RetXml;
}
示例2: InsertCDataNodeToDocumentNode
public static void InsertCDataNodeToDocumentNode()
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<a/>");
var cDataSection = xmlDocument.CreateCDataSection("data");
Assert.Throws<InvalidOperationException>(() => xmlDocument.InsertBefore(cDataSection, null));
}
示例3: SaveToXML
public static void SaveToXML(IntFontInfo fnt, string outPath)
{
XmlDocument doc = new XmlDocument();
XmlDeclaration decl = doc.CreateXmlDeclaration("1.0","utf-8",null);
XmlElement root = doc.CreateElement("font");
doc.InsertBefore(decl, doc.DocumentElement);
doc.AppendChild(root);
XmlElement common = doc.CreateElement("common");
common.SetAttribute("lineHeight", fnt.lineHeight.ToString());
common.SetAttribute("scaleW", fnt.scaleW.ToString());
common.SetAttribute("scaleH", fnt.scaleH.ToString());
common.SetAttribute("pages", "1");
root.AppendChild(common);
XmlElement pages = doc.CreateElement("pages");
XmlElement page1 = doc.CreateElement("page");
page1.SetAttribute("id", "0");
page1.SetAttribute("file", fnt.texName);
pages.AppendChild(page1);
root.AppendChild(pages);
XmlElement chars = doc.CreateElement("chars");
chars.SetAttribute("count", fnt.chars.Count.ToString());
foreach(IntChar c in fnt.chars){
XmlElement cNode = doc.CreateElement("char");
cNode.SetAttribute("id", c.id.ToString());
cNode.SetAttribute("x", c.x.ToString());
cNode.SetAttribute("y", c.y.ToString());
cNode.SetAttribute("width", c.width.ToString());
cNode.SetAttribute("height", c.height.ToString());
cNode.SetAttribute("xoffset", c.xoffset.ToString());
cNode.SetAttribute("yoffset", c.yoffset.ToString());
cNode.SetAttribute("xadvance", c.xadvance.ToString());
chars.AppendChild(cNode);
}
root.AppendChild(chars);
XmlElement kernings = doc.CreateElement("kernings");
kernings.SetAttribute("count", fnt.kernings.Count.ToString());
foreach(IntKerning k in fnt.kernings){
XmlElement kNode = doc.CreateElement("kerning");
kNode.SetAttribute("first", k.first.ToString());
kNode.SetAttribute("second", k.second.ToString());
kNode.SetAttribute("amount", k.amount.ToString());
kernings.AppendChild(kNode);
}
root.AppendChild(kernings);
doc.Save(outPath);
}
示例4: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string sSiteMapFilePath = HttpRuntime.AppDomainAppPath + "sitemap.xml";
var fi = new FileInfo(sSiteMapFilePath);
//if (fi.Exists && fi.LastWriteTime < DateTime.Now.AddHours(-1))
//{ // only allow it to be written once an hour in case someone spams this page (so it doesnt crash the site)
_xd = new XmlDocument();
XmlNode rootNode = _xd.CreateElement("urlset");
// add namespace
var attrXmlNS = _xd.CreateAttribute("xmlns");
attrXmlNS.InnerText = "http://www.sitemaps.org/schemas/sitemap/0.9";
rootNode.Attributes.Append(attrXmlNS);
//add img namespace
var attrXmlNS2 = _xd.CreateAttribute("xmlns:image");
attrXmlNS2.InnerText = "http://www.google.com/schemas/sitemap-image/1.1";
rootNode.Attributes.Append(attrXmlNS2);
// home page
rootNode.AppendChild(GenerateUrlNode("http://www.how-to-asp.net", DateTime.Now, "hourly", "1.00", "http://myimage.com"));
// ADD THE REST OF YOUR URL'S HERE
// append all nodes to the xmldocument and save it to sitemap.xml
_xd.AppendChild(rootNode);
_xd.InsertBefore(_xd.CreateXmlDeclaration("1.0", "UTF-8", null), rootNode);
_xd.Save(sSiteMapFilePath);
// PING SEARCH ENGINES TO LET THEM KNOW YOU UPDATED YOUR SITEMAP
// resubmit to google
//System.Net.WebRequest reqGoogle = System.Net.WebRequest.Create("http://www.google.com/webmasters/tools/ping?sitemap=" + HttpUtility.UrlEncode("http://www.how-to-asp.net/sitemap.xml"));
//reqGoogle.GetResponse();
//// resubmit to ask
//System.Net.WebRequest reqAsk = System.Net.WebRequest.Create("http://submissions.ask.com/ping?sitemap=" + HttpUtility.UrlEncode("http://www.how-to-asp.net/sitemap.xml"));
//reqAsk.GetResponse();
//// resubmit to yahoo
//System.Net.WebRequest reqYahoo = System.Net.WebRequest.Create("http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=YahooDemo&url=" + HttpUtility.UrlEncode("http://www.how-to-asp.net/sitemap.xml"));
//reqYahoo.GetResponse();
//// resubmit to bing
//System.Net.WebRequest reqBing = System.Net.WebRequest.Create("http://www.bing.com/webmaster/ping.aspx?siteMap=" + HttpUtility.UrlEncode("http://www.how-to-asp.net/sitemap.xml"));
//reqBing.GetResponse();
}
示例5: ToXmlDocument
public static XmlDocument ToXmlDocument(this XDocument xDocument)
{
var xmlDocument = new XmlDocument();
using (var xmlReader = xDocument.CreateReader())
{
xmlDocument.Load(xmlReader);
}
var xDeclaration = xDocument.Declaration;
if (xDeclaration != null)
{
var xmlDeclaration = xmlDocument.CreateXmlDeclaration(
xDeclaration.Version,
xDeclaration.Encoding,
xDeclaration.Standalone);
xmlDocument.InsertBefore(xmlDeclaration, xmlDocument.FirstChild);
}
return xmlDocument;
}
示例6: Write_Computer_List
public void Write_Computer_List(string[] filenames)
{
XmlDocument xd = new XmlDocument();
XmlDeclaration xdec = xd.CreateXmlDeclaration("1.0", "utf-8", null);
xd.InsertBefore(xdec, xd.DocumentElement);
XmlElement xeroot = xd.CreateElement("Computers");
xd.AppendChild(xeroot);
foreach (string K in filenames)
{
string fname;
fname = K.ToString();
//getSerialNo(fname);
XmlElement xeComputer = xd.CreateElement("Computer");
xeroot.AppendChild(xeComputer);
XmlAttribute xa = xd.CreateAttribute("Name");
xa.Value = K.ToString();
xeComputer.Attributes.Append(xa);
}
xd.Save(Server.MapPath("..//Files//Asset.xml"));
}
开发者ID:progressiveinfotech,项目名称:PRO_FY13_40_Helpdesk-Support-and-Customization_TerexBest,代码行数:22,代码来源:MasterAsset.master.cs
示例7: WriteOut
//Method used to write out the log file once the game has completed
//takes bool that indicates whether the session was properly completed
public void WriteOut(bool completed)
{
//Generate the file name
GenerateNewTimestamp();
//Set up the xml document
XmlDocument xml = new XmlDocument();
//Create declaration
XmlDeclaration dec = xml.CreateXmlDeclaration("1.0", "utf-8",null);
xml.AppendChild(dec);
// Create the root element "session"
XmlElement session = xml.CreateElement("session");
xml.InsertBefore(dec, xml.DocumentElement);
xml.AppendChild(session);
if(gm.SType == GameManager.SessionType.Spatial) WriteOutSpatial(xml,session);
else if(gm.SType == GameManager.SessionType.Inhibition) WriteOutInhibition(xml,session);
else if (gm.SType == GameManager.SessionType.Star) WriteOutStar(xml,session);
else if (gm.SType == GameManager.SessionType.Implicit) WriteOutImplicit(xml,session);
else if (gm.SType == GameManager.SessionType.Associate) WriteOutAssociate(xml,session);
else if (gm.SType == GameManager.SessionType.Stopping) WriteOutStopping(xml,session);
//Save the file in the correct spot
if(completed){
NeuroLog.Debug("Saving log file: "+ Path.Combine(LogFilesPath, statsXML));
xml.Save(Path.Combine(LogFilesPath, statsXML));
}
else{
NeuroLog.Debug("Saving unfinished log file: "+ Path.Combine(UnfinishedSessionPath, statsXML));
xml.Save(Path.Combine(UnfinishedSessionPath,statsXML));
}
}
示例8: GenerateSitemapIndex
private void GenerateSitemapIndex()
{
string sSiteMapFilePath = HttpRuntime.AppDomainAppPath + "sitemap_index.xml";
if (!File.Exists(HttpRuntime.AppDomainAppPath + "sitemap_index.xml"))
{
List<SitemapInfo> items = MenuManagerDataController.GetSiteMapPages(GetUsername, GetCurrentCultureName);
FileInfo fi = new FileInfo(sSiteMapFilePath);
xd = new XmlDocument();
XmlNode rootNode = xd.CreateElement("urlset");
XmlAttribute attrXmlNS = xd.CreateAttribute("xmlns");
attrXmlNS.InnerText = "http://www.sitemaps.org/schemas/sitemap/0.9";
rootNode.Attributes.Append(attrXmlNS);
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
rootNode.AppendChild(GenerateIndexNode(Page.Request.Url.Scheme + "://" + Request.Url.Authority + GetApplicationName + "/sitemap_" + GetPortalID + ".xml"));
xd.AppendChild(rootNode);
xd.InsertBefore(xd.CreateXmlDeclaration("1.0", "UTF-8", null), rootNode);
xd.Save(sSiteMapFilePath);
}
else
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(HttpRuntime.AppDomainAppPath + "sitemap_index.xml");
XmlNode node = GenerateIndexNode(Page.Request.Url.Scheme + "://" + Request.Url.Authority + GetApplicationName + "/sitemap_" + GetPortalID + ".xml");
XmlNode childNode = xmlDoc.DocumentElement;
childNode.InsertAfter(node, childNode.LastChild);
xmlDoc.Save(sSiteMapFilePath);
}
}
示例9: GenerateSitemap
private void GenerateSitemap()
{
if (!File.Exists(HttpRuntime.AppDomainAppPath + "sitemap_" + GetPortalID + ".xml"))
{
GenerateSitemapIndex();
}
else
{
XmlDocument doc = new XmlDocument();
doc.Load(HttpRuntime.AppDomainAppPath + "sitemap_index.xml");
XmlNodeList nodeList = doc.GetElementsByTagName("lastmod");
foreach (XmlNode xmlNode in nodeList)
{
xmlNode.InnerText = DateTime.Now.ToString();
}
}
string sSiteMapFilePath = HttpRuntime.AppDomainAppPath + "sitemap_" + GetPortalID + ".xml";
List<SitemapInfo> items = MenuManagerDataController.GetSiteMapPages(GetUsername, GetCurrentCultureName);
FileInfo fi = new FileInfo(sSiteMapFilePath);
xd = new XmlDocument();
XmlNode rootNode = xd.CreateElement("urlset");
XmlAttribute attrXmlNS = xd.CreateAttribute("xmlns");
attrXmlNS.InnerText = "http://www.sitemaps.org/schemas/sitemap/0.9";
rootNode.Attributes.Append(attrXmlNS);
ChangeFreuency = ddlChangeFrequency.SelectedItem.ToString();
PriorityValues = ddlPriorityValues.SelectedItem.ToString();
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
foreach (SitemapInfo info in items)
{
DateTime Updated;
if (info.UpdatedOn == null || info.UpdatedOn == "")
{
Updated = DateTime.Parse(info.AddedOn);
}
else
{
Updated = DateTime.Parse(info.UpdatedOn);
}
//Valid option for changefreq:(always,hourly,daily,weekly,monthly,yearly,never)
//Valid priority values have range interval [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0].
string urlpath = info.PortalID > 1 ? string.Format("/portal/{0}{1}", info.PortalName, info.TabPath) : info.TabPath;
rootNode.AppendChild(GenerateUrlNode(Page.Request.Url.Scheme + "://" + Request.Url.Authority + GetApplicationName + urlpath + SageFrameSettingKeys.PageExtension, Updated, ChangeFreuency, PriorityValues));
}
xd.AppendChild(rootNode);
xd.InsertBefore(xd.CreateXmlDeclaration("1.0", "UTF-8", null), rootNode);
xd.Save(sSiteMapFilePath);
}
示例10: InsertAttributeNodeToAttributeNode
public static void InsertAttributeNodeToAttributeNode()
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<root attr='value'/>");
var attribute = xmlDocument.CreateAttribute("attr");
Assert.Throws<InvalidOperationException>(() => xmlDocument.InsertBefore(attribute, null));
}
示例11: TestXmlDocumentAddElement
// Test adding an element to the document.
public void TestXmlDocumentAddElement()
{
XmlDocument doc = new XmlDocument();
// Add an element to the document.
XmlElement element = doc.CreateElement("foo");
AssertNull("XmlElement (1)", element.ParentNode);
AssertEquals("XmlElement (2)", doc, element.OwnerDocument);
doc.AppendChild(element);
AssertEquals("XmlElement (3)", doc, element.ParentNode);
AssertEquals("XmlElement (4)", doc, element.OwnerDocument);
// Try to add it again, which should fail this time.
try
{
doc.AppendChild(element);
Fail("adding XmlElement node twice");
}
catch(InvalidOperationException)
{
// Success
}
try
{
doc.PrependChild(element);
Fail("prepending XmlElement node twice");
}
catch(InvalidOperationException)
{
// Success
}
// Adding an XmlDeclaration after should fail.
XmlDeclaration decl =
doc.CreateXmlDeclaration("1.0", null, null);
try
{
doc.AppendChild(decl);
Fail("appending XmlDeclaration after XmlElement");
}
catch(InvalidOperationException)
{
// Success
}
// But adding XmlDeclaration before should succeed.
doc.PrependChild(decl);
// Adding a document type after should fail.
XmlDocumentType type =
doc.CreateDocumentType("foo", null, null, null);
try
{
doc.AppendChild(type);
Fail("appending XmlDocumentType");
}
catch(InvalidOperationException)
{
// Success
}
// Adding a document type before should succeed.
doc.InsertBefore(type, element);
}
示例12: TestXmlDocumentAddXmlDeclaration
// Test adding an XML declaration to the document.
public void TestXmlDocumentAddXmlDeclaration()
{
XmlDocument doc = new XmlDocument();
// Add the declaration.
XmlDeclaration decl =
doc.CreateXmlDeclaration("1.0", null, null);
AssertNull("XmlDeclaration (1)", decl.ParentNode);
AssertEquals("XmlDeclaration (2)", doc, decl.OwnerDocument);
doc.AppendChild(decl);
AssertEquals("XmlDeclaration (3)", doc, decl.ParentNode);
AssertEquals("XmlDeclaration (4)", doc, decl.OwnerDocument);
// Try to add it again, which should fail this time.
try
{
doc.AppendChild(decl);
Fail("adding XmlDeclaration node twice");
}
catch(InvalidOperationException)
{
// Success
}
try
{
doc.PrependChild(decl);
Fail("prepending XmlDeclaration node twice");
}
catch(InvalidOperationException)
{
// Success
}
// Adding a document type before should fail.
XmlDocumentType type =
doc.CreateDocumentType("foo", null, null, null);
try
{
doc.PrependChild(type);
Fail("prepending XmlDocumentType");
}
catch(InvalidOperationException)
{
// Success
}
// Adding a document type after should succeed.
doc.AppendChild(type);
// Adding an element before should fail.
XmlElement element = doc.CreateElement("foo");
try
{
doc.PrependChild(element);
Fail("prepending XmlElement");
}
catch(InvalidOperationException)
{
// Success
}
// Adding the element between decl and type should fail.
try
{
doc.InsertAfter(element, decl);
Fail("inserting XmlElement between XmlDeclaration " +
"and XmlDocumentType");
}
catch(InvalidOperationException)
{
// Success
}
try
{
doc.InsertBefore(element, type);
Fail("inserting XmlElement between XmlDeclaration " +
"and XmlDocumentType (2)");
}
catch(InvalidOperationException)
{
// Success
}
// Adding an element after should succeed.
doc.AppendChild(element);
}
示例13: btnsave_Click
protected void btnsave_Click(object sender, EventArgs e)
{
try
{
if (txtinv.Text != "")
{
DirectoryInfo di = new DirectoryInfo("C://Asset//NetworkData");
FileInfo[] fi = di.GetFiles();
bool statusFile;
statusFile = false;
int countfile = fi.GetLength(0);
//int i = 0;
//filenames = new string[countfile];
string currentfilename;
string txtcurrentfilename;
txtcurrentfilename = txtinv.Text + ".";
foreach (FileInfo K in fi)
{
string[] fname = K.Name.Split(new char[] { 'x' });
currentfilename = fname[0].ToString();
if (currentfilename.Trim() == txtcurrentfilename.Trim())
{
statusFile = true;
}
}
if (!statusFile)
{
XmlDocument xd = new XmlDocument();
XmlDeclaration xdec = xd.CreateXmlDeclaration("1.0", "utf-8", null);
xd.InsertBefore(xdec, xd.DocumentElement);
XmlElement xeroot = xd.CreateElement("Devices");
xd.AppendChild(xeroot);
string tempfilename;
tempfilename = txtinv.Text + ".xml";
xd.Save("c://Asset//NetworkData//" + tempfilename);
//Create the XmlDocument.
XmlDocument doc = new XmlDocument();
doc.LoadXml(("<Device><Created_on>" + txtInvntDate.Text + "</Created_on> <Computer_name>" + txtdeviceName.Text + "</Computer_name><System> <Description>" + txtDesc.Text + "</Description><Up_time>" + txtuptime.Text + "</Up_time><Platform_ID>" + txtPlatform.Text + " </Platform_ID><Contact>" + txtContact.Text + "</Contact><Location>" + txtLocation.Text + "</Location></System><Ip_addresses><Ip_address><Ip_address>" + txtinv.Text + "</Ip_address></Ip_address></Ip_addresses></Device>"));
//Save the document to a file.
doc.Save("c://Asset//NetworkData//" + tempfilename);
txtinv.Text = "";
txtInvntDate.Text = "";
txtdeviceName.Text = "";
txtDesc.Text = "";
txtuptime.Text = "";
txtPlatform.Text = "";
txtContact.Text = "";
txtLocation.Text = "";
}
else
{
string myScript;
myScript = "<script language=javascript>alert('Following IP Address already Exist,Enter different IP Address'); </script>";
Page.RegisterClientScriptBlock("MyScript", myScript);
}
}
}
catch (Exception ex)
{
string myScript;
myScript = "<script language=javascript>alert('Exception - '" + ex + "');</script>";
Page.RegisterClientScriptBlock("MyScript", myScript);
return;
}
}
开发者ID:progressiveinfotech,项目名称:PRO_FY13_40_Helpdesk-Support-and-Customization_EIH,代码行数:75,代码来源:Add_Network_Inventory.aspx.cs
示例14: NewsRSS
public NewsRSS()
{
_rss = new XmlDocument();
XmlDeclaration xmlDeclaration = _rss.CreateXmlDeclaration("1.0", "utf-8", null);
_rss.InsertBefore(xmlDeclaration, _rss.DocumentElement);
XmlElement rssElement = _rss.CreateElement("rss");
XmlAttribute rssVersionAttribute = _rss.CreateAttribute("version");
rssVersionAttribute.InnerText = "2.0";
rssElement.Attributes.Append(rssVersionAttribute);
_rss.AppendChild(rssElement);
}
示例15: DoGetXml
private XmlDocument DoGetXml()
{
XmlDocument doc = new XmlDocument();
XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.InsertBefore(xmlDeclaration, doc.DocumentElement);
XmlElement fractal = doc.CreateElement("fractal");
fractal.SetAttribute("exponent", string.Format("{0:0.00}", m_paletteExponent));
fractal.SetAttribute("name", m_palette.Name);
doc.AppendChild(fractal);
XmlElement settings = m_settings.GetXmlNode(doc);
fractal.AppendChild(settings);
XmlElement palette = m_palette.GetXmlNode(doc);
fractal.AppendChild(palette);
return doc;
}