本文整理汇总了C#中System.Xml.XmlDocument.RemoveAll方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.RemoveAll方法的具体用法?C# XmlDocument.RemoveAll怎么用?C# XmlDocument.RemoveAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.RemoveAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckMarkerPaths
public void CheckMarkerPaths(string fileName)
{
DirectoryInfo markerDir = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(fileName), "Markers"));
XmlDocument doc = new XmlDocument();
doc.Load(fileName);
if (doc.GetElementsByTagName("markers").Count == 0) return;
XmlNodeList markerList = doc.GetElementsByTagName("marker");
if (markerList.Count > 0)
{
foreach (XmlNode node in markerList)
{
if(node.Attributes == null || node.Attributes["id"] == null)
throw new UserMessageException("Marker id doesn't exist for 'Marker' element in file {1}", fileName);
if (node.Attributes == null || node.Attributes["name"] == null)
throw new UserMessageException("Marker name doesn't exist for 'Marker' element in file {1}", fileName);
string id = node.Attributes["id"].Value;
string name = node.Attributes["name"].Value;
FileInfo[] f = markerDir.GetFiles(string.Format("{0}.*", id), SearchOption.TopDirectoryOnly);
if (f.Length == 0)
{
throw new UserMessageException("Marker image not found with id {0} and name {1} in file {2}", id, name, fileName);
}
}
}
doc.RemoveAll();
doc = null;
}
示例2: SaveAsXML
private void SaveAsXML()
{
DataTable dt = (DataTable)bindingSource.DataSource;
XmlDocument doc = new XmlDocument();
XmlNode rootNode = doc.CreateNode(XmlNodeType.Element,"root", null);
foreach (DataRow row in dt.Rows)
{
object[] values = row.ItemArray;
XmlNode prop = doc.CreateNode(XmlNodeType.Element, "propertyset", null);
XmlNode name = doc.CreateNode(XmlNodeType.Element, "name", null);
XmlNode value = doc.CreateNode(XmlNodeType.Element, "value", null);
name.InnerText = (string)values[0];
value.InnerText = (string)values[1];
prop.AppendChild(name);
prop.AppendChild(value);
rootNode.AppendChild(prop);
}
doc.AppendChild(rootNode);
string file = Path.Combine(GetExecutingDir(), xmlPropertyFileName);
if (File.Exists(file))
{
File.Delete(file);
}
doc.Save(file);
doc.RemoveAll();
doc = null;
}
示例3: Save
public bool Save(string path)
{
bool saved = true;
XmlDocument m_Xdoc = new XmlDocument();
try
{
m_Xdoc.RemoveAll();
XmlNode node = m_Xdoc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
m_Xdoc.AppendChild(node);
node = m_Xdoc.CreateComment($" Profile Configuration Data. {DateTime.Now} ");
m_Xdoc.AppendChild(node);
node = m_Xdoc.CreateWhitespace("\r\n");
m_Xdoc.AppendChild(node);
node = m_Xdoc.CreateNode(XmlNodeType.Element, "Profile", null);
m_Xdoc.AppendChild(node);
m_Xdoc.Save(path);
}
catch
{
saved = false;
}
return saved;
}
示例4: GetBlockSources
public static Dictionary<string, string> GetBlockSources(string path)
{
Dictionary<string, string> ret = new Dictionary<string, string>();
XmlDocument doc = new XmlDocument();
doc.Load(path);
foreach (XmlNode node in doc.GetElementsByTagName("block"))
{
string id = node.Attributes["id"].Value;
if (node.Attributes["src"] != null)
{
ret.Add(id, node.Attributes["src"].Value);
}
string fontPath = GetFontPath(node);
if (fontPath != string.Empty)
{
ret.Add(id, fontPath);
}
}
doc.RemoveAll();
doc = null;
return (ret);
}
示例5: Save
//add any properties you need, declarations and xelements to methods below
public static void Save()
{
var document = new XmlDocument();
document.Load(path);
document.RemoveAll();
//add to doc somehow?
document.Save(path);
}
示例6: Execute
public static void Execute(string inputFile, string output)
{
if (!_insertHomographClass && !_insertSenseNumClass)
return;
var xmlDoc = new XmlDocument();
xmlDoc.XmlResolver = FileStreamXmlResolver.GetNullResolver();
var nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
const string xhtmlns = "http://www.w3.org/1999/xhtml";
nsmgr.AddNamespace("x", xhtmlns);
xmlDoc.Load(inputFile);
var changed = false;
if (_insertSenseNumClass)
{
var senseNums = xmlDoc.SelectNodes("//x:span[@class='headref']/x:span", nsmgr);
foreach (XmlElement senseNum in senseNums)
{
if (!senseNum.HasAttribute("class"))
{
senseNum.SetAttribute("class", "revsensenumber");
changed = true;
}
}
}
if (_insertHomographClass)
{
var nodes = xmlDoc.SelectNodes("//x:span[@class='headref']/text()", nsmgr);
foreach (XmlNode node in nodes)
{
var match = Regex.Match(node.InnerText, "([^0-9]*)([0-9]*)");
if (match.Groups[2].Length > 0)
{
var homographNode = xmlDoc.CreateElement("span", xhtmlns);
homographNode.SetAttribute("class", "revhomographnumber");
homographNode.InnerText = match.Groups[2].Value;
node.InnerText = match.Groups[1].Value;
node.ParentNode.InsertAfter(homographNode, node);
changed = true;
}
}
}
if (changed)
{
var xmlWriter = XmlWriter.Create(output);
xmlDoc.WriteTo(xmlWriter);
xmlWriter.Close();
}
xmlDoc.RemoveAll();
}
示例7: ProblemXML
public ProblemXML(String filename,bool isReadOnly)
{
FileName = filename;
xd = new XmlDocument();
if (isReadOnly)
{
if (File.Exists(FileName))
{
try
{
xd.Load(FileName);
}
catch
{
Console.WriteLine("文件不是有效的XML");
isError = true;
}
}
else
{
Console.WriteLine("文件不存在");
isError = true;
}
}
else
{
if (FileName != "")
{
XmlElement xmlelem;
XmlNode xmlnode;
xd.RemoveAll();
//加入xml声明
xmlnode = xd.CreateNode(XmlNodeType.XmlDeclaration, "", "");
xd.AppendChild(xmlnode);
//加入一个根元素
xmlelem = xd.CreateElement("", "ROOT", "");
xd.AppendChild(xmlelem);
xd.Save(FileName);
}
else
{
Console.WriteLine("文件不存在");
isError = true;
}
}
}
示例8: GetGuids
internal List<SetGuid> GetGuids()
{
List<SetGuid> ret = new List<SetGuid>();
XmlDocument doc = new XmlDocument();
FileInfo[] d = new DirectoryInfo(p).GetFiles("*.xml");
FileInfo f = null;
if (d.Length > 0)
{
f = d[0];
}
if (f != null)
{
doc.Load(f.FullName);
XmlNode n = doc.GetElementsByTagName("set").Item(0);
Guid s = Guid.Empty;
if (n.Attributes["id"] != null)
{
s = Guid.Parse(n.Attributes["id"].Value);
}
XmlNodeList l = doc.GetElementsByTagName("card");
foreach (XmlNode node in l)
{
if (node.Attributes["id"] != null)
{
Guid g = Guid.Parse(node.Attributes["id"].Value);
SetGuid setguid = new SetGuid()
{
set = s,
card = g
};
ret.Add(setguid);
}
}
}
doc.RemoveAll();
doc = null;
return (ret);
}
示例9: OfficeXML
public OfficeXML(String filename)
{
FileName = filename;
XmlDocument xd = new XmlDocument();
if (FileName != "")
{
XmlElement xmlelem;
XmlNode xmlnode;
if (File.Exists(FileName))
{
try
{
xd.Load(FileName);
}
catch
{
xd.RemoveAll();
//加入xml声明
xmlnode = xd.CreateNode(XmlNodeType.XmlDeclaration, "", "");
xd.AppendChild(xmlnode);
//加入一个根元素
xmlelem = xd.CreateElement("", "ROOT", "");
xd.AppendChild(xmlelem);
}
}
else
{
//加入xml声明
xmlnode = xd.CreateNode(XmlNodeType.XmlDeclaration, "", "");
xd.AppendChild(xmlnode);
//加入一个根元素
xmlelem = xd.CreateElement("", "ROOT", "");
xd.AppendChild(xmlelem);
}
xd.Save(FileName);
}
}
示例10: PPreview_Click
private void PPreview_Click(object sender, EventArgs e)
{
if (this.PrintTemplateList.SelectedItem == null)
{
BusinessLogic.MyMessageBox("Please first select a template for printing from the [Choose Template] section");
}
else
{
TextWriter writer = null;
try
{
if (this.SelectedColumnList.Items.Count < 1)
{
throw new Exception("No columns selected!");
}
XmlDocument doc = new XmlDocument();
int num = 100 / (this.SelectedColumnList.Items.Count + 1);
doc.LoadXml("<center><table border=\"1\" width=\"" + Convert.ToString((int) (num * this.SelectedColumnList.Items.Count)) + "%\"></table></center>");
XmlNode node = doc.DocumentElement.FirstChild.AppendChild(doc.CreateElement("tr"));
foreach (object obj2 in this.SelectedColumnList.Items)
{
XmlNode node2 = node.AppendChild(doc.CreateElement("td"));
XmlNode node3 = doc.CreateNode(XmlNodeType.Attribute, "width", null);
node3.Value = Convert.ToString(num) + "%";
node2.Attributes.SetNamedItem(node3);
node2.AppendChild(doc.CreateElement("b")).InnerText = Convert.ToString(obj2);
}
foreach (DataRow row in this.dsSrc.Tables[0].Rows)
{
XmlNode node5 = doc.DocumentElement.FirstChild.AppendChild(doc.CreateElement("tr"));
foreach (object obj2 in this.SelectedColumnList.Items)
{
XmlNode node6 = node5.AppendChild(doc.CreateElement("td"));
XmlNode node7 = doc.CreateNode(XmlNodeType.Attribute, "width", null);
node7.Value = Convert.ToString(num) + "%";
node6.Attributes.SetNamedItem(node7);
node6.InnerText = Convert.ToString(row[Convert.ToString(obj2)]);
}
}
string str2 = this.ApplyTemplate(doc);
doc.RemoveAll();
writer = new StreamWriter(@".\PrintCache\PrintDocument.html", false, Encoding.ASCII);
writer.Write(str2);
writer.WriteLine("<script language=\"javascript\">");
writer.WriteLine("\tvar WebBrowser='<OBJECT ID=WebBrowser1 WIDTH=0 HEIGHT=0 CLASSID=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2></OBJECT>';");
writer.WriteLine("\tdocument.write(WebBrowser);");
writer.WriteLine("\tWebBrowser1.ExecWB(7,0);");
writer.WriteLine("</script>");
writer.Close();
writer = null;
Process.Start("iexplore.exe", "\"" + Application.StartupPath + "\\PrintCache\\PrintDocument.html\"");
}
catch (Exception exception)
{
if (writer != null)
{
writer.Close();
writer = null;
}
BusinessLogic.MyMessageBox(exception.Message);
BusinessLogic.MyMessageBox("Document for printing could not be formed!");
}
}
}
示例11: Start
// Read XML document from file, if not exist, start new XML document.
public bool Start(String filename, String docName)
{
m_filename = filename;
m_name = System.IO.Path.GetFileName(filename);
m_xdoc = new XmlDocument();
m_toplevel = null;
bool fileExist = System.IO.File.Exists(m_filename);
try
{
m_xdoc.Load(m_filename);
m_toplevel = m_xdoc.ChildNodes[1];
//m_version = GetInt(m_xdoc, "FileVersion", 0);
if (m_toplevel.Name != docName)
m_toplevel = null;
else
{
m_verattr = m_toplevel.Attributes["FileVersion"];
m_version = int.Parse(m_verattr.Value);
}
}
catch (Exception ex)
{
if (fileExist)
{
DebugLogger.Instance().LogError(m_name + ": " + ex.Message);
m_xdoc.RemoveAll();
}
m_toplevel = null;
}
if (m_toplevel == null)
{
NewDocument(docName);
}
return fileExist;
}
示例12: openDefinitionButton_Click
private void openDefinitionButton_Click(object sender, EventArgs e)
{
if (definitionOpenDialog.ShowDialog() != DialogResult.Cancel)
{
string def = definitionOpenDialog.FileName;
rootDirTextBox.Text = Path.GetDirectoryName(def);
XmlDocument doc = new XmlDocument();
doc.Load(def);
XmlNodeList list = doc.GetElementsByTagName("proxygen");
string relPath = list.Item(0).Attributes["definitionsrc"].Value;
proxydefPathTextBox.Text = Path.Combine(rootDirTextBox.Text, relPath);
doc.RemoveAll();
doc = null;
if (!ValidateTemplatePaths())
{
proxydefPathTextBox.Text = string.Empty;
rootDirTextBox.Text = string.Empty;
MessageBox.Show("Template contains an invalid image path");
}
else
{
generateProxyButton.Enabled = true;
}
}
}
示例13: LoadXML
private void LoadXML(string path)
{
DataTable dt = SetupDataTable();
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNodeList list = doc.GetElementsByTagName("propertyset");
foreach (XmlNode node in list)
{
string[] values = new string[2];
values[0] = node.ChildNodes[0].InnerText;
values[1] = node.ChildNodes[1].InnerText;
dt.Rows.Add(values);
}
bindingSource.DataSource = dt;
doc.RemoveAll();
doc = null;
}
示例14: Main
static void Main(string[] args)
{
Console.WriteLine("=========================================");
Console.WriteLine("= " + DateTime.Now.AddDays(-1).ToString("MMMM dd, yyyy").ToUpper().PadLeft(17) + " - " + DateTime.Now.ToString("MMMM dd, yyyy").ToUpper().PadRight(17) + " =");
Console.WriteLine("=========================================");
ArrayList al = new ArrayList(); //NON-FG
ArrayList al2 = new ArrayList(); //FG
string invoiceNum = "";
XmlDocument doc = new XmlDocument();
methods me = new methods();
string lineItemNum = "";
//NON-FINISHED GOODS THAT WERE INVOICED
al = me.getTodaysInvoices();
foreach (object[] row in al)
{
Console.WriteLine("WIKey:" + row[0].ToString());
for (int i = 1; i < row.Length; i++)
{
Console.WriteLine(" -"+ row[i] as string);
}
invoiceNum = row[1].ToString(); //2nd column in vw_PTI_invoice
lineItemNum = row[4].ToString(); //5th column in vw_PTI_invoice
Console.WriteLine("Line Item ID: " + lineItemNum);
doc = me.createInvoiceByLineItemRequest(invoiceNum, lineItemNum);
me.parseResponse(me.sendXmlRequest(doc));
try
{
doc.Save("../../XML/" + invoiceNum + " - " + lineItemNum + "_req.xml");
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
doc.RemoveAll();
int settlementNeeded = Convert.ToInt32(row[7]);
if (settlementNeeded == 1)
{
Console.WriteLine("CREDIT CARD SETTLEMENT FOR " + lineItemNum +"\n");
string orderID = me.getOrderID(lineItemNum);
XmlDocument d = me.createSettlementByOrderRequest(orderID);
me.parseResponse_settlement(me.sendXmlRequest_Settlement(d));
d.RemoveAll();
}
Console.WriteLine("========================================");
}
//FINISHED GOODS ORDERS THAT WERE INVOICED
al2 = me.getTodaysFGInvoices();
foreach (object[] row in al2)
{
Console.WriteLine("WIKey:" + row[0].ToString());
for (int i = 0; i < row.Length; i++)
{
Console.WriteLine(" -" + row[i] as string);
}
invoiceNum = row[2].ToString(); //3rd column in vw_PTI_invoiceFG
string hold = row[6] as string; //8th column in vw_PTI_invoiceFG
//string fgOrderNum = me.finGoodSubstring(hold);
string FGwebOrderID = hold;
string s = me.getOrderID(FGwebOrderID);
Console.WriteLine("Web Order ID: " + hold /*FGwebOrderID*/ + "\n");
doc = me.createInvoiceByLineItemRequest(invoiceNum, hold/*FGwebOrderID*/);
me.parseResponse(me.sendXmlRequest(doc));
doc.RemoveAll();
if (me.needsSettlement(s))
{
Console.WriteLine("CREDIT CARD SETTLEMENT FOR FG" + FGwebOrderID + "Ord:" + s + "\n");
XmlDocument d = me.createSettlementByOrderRequest(s);
me.parseResponse_settlement(me.sendXmlRequest_Settlement(d));
d.RemoveAll();
}
Console.WriteLine("========================================");
}
//
// MANUAL FG ORDER INVOICE
//
/*al2 = me.getTodaysFGInvoices();
foreach (object[] row in al2)
{
Console.WriteLine("WIKey:" + row[0].ToString());
for (int i = 0; i < row.Length; i++)
{
//.........这里部分代码省略.........
示例15: buildNotation
private string buildNotation(String GraphicsCode, String XMLData)
{
try
{
//Load data
XmlReader datareader = XmlReader.Create(new StringReader(XMLData));
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(XMLData);
XmlNode XmlDataNode = xdoc.DocumentElement;
string dataNodeName = XmlDataNode.Name;
xdoc.RemoveAll();
//create transformation
XmlElement stylesheet = xdoc.CreateElement("stylesheet", "xsl");
stylesheet.SetAttribute("xmlns:xsl", "http://www.w3.org/1999/XSL/Transform");
stylesheet.Prefix = "xsl";
stylesheet.SetAttribute("version", "1.0");
if (visType == VisualisationType.XAML)
{
stylesheet.SetAttribute("xmlns:x", "http://schemas.microsoft.com/winfx/2006/xaml");
stylesheet.SetAttribute("xmlns:local", "clr-namespace:CONVErT;assembly=CONVErT");
stylesheet.SetAttribute("xmlns", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
}
else if (visType == VisualisationType.SVG)
{
//don't know what will go here for now! Possibly script
//to use for adding interaction to SVG
}
XmlElement mainTemplate = stylesheet.OwnerDocument.CreateElement("xsl", "template", "http://www.w3.org/1999/XSL/Transform");
//mainTemplate.Prefix = "xsl";
stylesheet.AppendChild(mainTemplate);
XmlAttribute matchAttr = xdoc.CreateAttribute("match");
matchAttr.Value = "/";
mainTemplate.Attributes.Append(matchAttr);
XmlElement callTemplate = xdoc.CreateElement("xsl", "apply-templates", "http://www.w3.org/1999/XSL/Transform");
mainTemplate.AppendChild(callTemplate);
XmlAttribute selectAttr = xdoc.CreateAttribute("select");
string selectStr = dataNodeName;//templates.First().Attributes.GetNamedItem("match").Value;
selectAttr.AppendChild(xdoc.CreateTextNode(selectStr) as XmlNode);
callTemplate.Attributes.Append(selectAttr);
//create transforamtion
Collection<XmlNode> transXSLTemplates = parseAnnotatedGraphics(GraphicsCode, dataNodeName, XmlDataNode);
foreach (XmlNode x in transXSLTemplates)
stylesheet.AppendChild(stylesheet.OwnerDocument.ImportNode(x, true));
//for removing text
XmlNode applytemplatesText = stylesheet.OwnerDocument.CreateElement("xsl", "template", "http://www.w3.org/1999/XSL/Transform");
//valueofNode.Prefix = "xsl";
XmlAttribute selectAttr1 = stylesheet.OwnerDocument.CreateAttribute("match");
selectAttr1.Value = "text()";
applytemplatesText.Attributes.Append(selectAttr1);
stylesheet.AppendChild(applytemplatesText);
String transXSL = prettyPrinter.PrintToString(stylesheet);
//MessageBox.Show(transXSL);
XmlReader xslreader = XmlReader.Create(new StringReader(transXSL));
//transformation output
StringBuilder output = new StringBuilder("");
XmlWriter outputwriter = XmlWriter.Create(output);
//run transformation
XslCompiledTransform myXslTransform = new XslCompiledTransform();
myXslTransform.Load(xslreader);
myXslTransform.Transform(datareader, outputwriter);
String s = prettyPrinter.PrintToString(output.ToString());
return s;
}
catch (CallforUseErrorException cuex)//with new annotations for @linkto it will not happen! but keep it just in case
{
logger.log("Error in use of callfor: Call for does not support attribute generation", ReportIcon.Error);
ReportStatusBar.ShowStatus("Error procesing annotated graphics: see exception!", ReportIcon.Error);
return null;
}
catch (Exception ex)
{
ReportStatusBar.ShowStatus("(createNotation): Something went wrong -> " + ex.Message, ReportIcon.Error);
return null;
}
}