本文整理汇总了C#中System.Xml.XmlDocument.CreateNode方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.CreateNode方法的具体用法?C# XmlDocument.CreateNode怎么用?C# XmlDocument.CreateNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.CreateNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToXml
public XmlElement ToXml(XmlDocument document)
{
XmlElement nodeNode = document.CreateElement("idmef:Node", "http://iana.org/idmef");
nodeNode.SetAttribute("ident", ident);
nodeNode.SetAttribute("category", EnumDescription.GetEnumDescription(category));
if (!string.IsNullOrEmpty(location))
{
XmlElement nodeSubNode = document.CreateElement("idmef:location", "http://iana.org/idmef");
XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "location", "http://iana.org/idmef");
subNode.Value = location;
nodeSubNode.AppendChild(subNode);
nodeNode.AppendChild(nodeSubNode);
}
if (!string.IsNullOrEmpty(name))
{
XmlElement nodeSubNode = document.CreateElement("idmef:name", "http://iana.org/idmef");
XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "name", "http://iana.org/idmef");
subNode.Value = name;
nodeSubNode.AppendChild(subNode);
nodeNode.AppendChild(nodeSubNode);
}
if ((address != null) && (address.Length > 0))
foreach (var a in address)
if (a != null) nodeNode.AppendChild(a.ToXml(document));
return nodeNode;
}
示例2: ToXml
public XmlElement ToXml(XmlDocument document)
{
XmlElement addressNode = document.CreateElement("idmef:Address", "http://iana.org/idmef");
addressNode.SetAttribute("ident", ident);
addressNode.SetAttribute("category", EnumDescription.GetEnumDescription(category));
if (!string.IsNullOrEmpty(vlanName)) addressNode.SetAttribute("vlan-name", vlanName);
if (vlanNum != null) addressNode.SetAttribute("vlan-num", vlanNum.ToString());
if (string.IsNullOrEmpty(address)) throw new InvalidOperationException("Address must have an address node.");
XmlElement addressSubNode = document.CreateElement("idmef:address", "http://iana.org/idmef");
XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "address", "http://iana.org/idmef");
subNode.Value = address;
addressSubNode.AppendChild(subNode);
addressNode.AppendChild(addressSubNode);
if (!string.IsNullOrEmpty(netmask))
{
addressSubNode = document.CreateElement("idmef:netmask", "http://iana.org/idmef");
subNode = document.CreateNode(XmlNodeType.Text, "idmef", "netmask", "http://iana.org/idmef");
subNode.Value = netmask;
addressSubNode.AppendChild(subNode);
addressNode.AppendChild(addressSubNode);
}
return addressNode;
}
示例3: ToXml
public XmlElement ToXml(XmlDocument document)
{
XmlElement addressNode = document.CreateElement("idmef:UserId", "http://iana.org/idmef");
addressNode.SetAttribute("ident", ident);
addressNode.SetAttribute("type", EnumDescription.GetEnumDescription(type));
if (!string.IsNullOrEmpty(tty)) addressNode.SetAttribute("tty", tty);
if (!string.IsNullOrEmpty(name))
{
XmlElement addressSubNode = document.CreateElement("idmef:name", "http://iana.org/idmef");
XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "name", "http://iana.org/idmef");
subNode.Value = name;
addressSubNode.AppendChild(subNode);
addressNode.AppendChild(addressSubNode);
}
if (number != null)
{
XmlElement addressSubNode = document.CreateElement("idmef:number", "http://iana.org/idmef");
XmlNode subNode = document.CreateNode(XmlNodeType.Text, "idmef", "number", "http://iana.org/idmef");
subNode.Value = number.ToString();
addressSubNode.AppendChild(subNode);
addressNode.AppendChild(addressSubNode);
}
return addressNode;
}
示例4: 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;
}
示例5: AddNewElement
public string AddNewElement(string filePathName, string parent)
{
//Here we load the XML file into the memory
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(filePathName);
//Here we create employee node without any namespace
XmlNode employeeNode = xmlDocument.CreateNode(XmlNodeType.Element, "employee", null);
//Here we define an attribute and add it to the employee node
XmlAttribute attribute = xmlDocument.CreateAttribute("id");
attribute.Value = "e8000";
employeeNode.Attributes.Append(attribute);
//Here we create name node without any namespace
XmlNode nameNode = xmlDocument.CreateNode(XmlNodeType.Element, "name", null);
nameNode.InnerText = "Arash";
employeeNode.AppendChild(nameNode);
//Here we create job node without any namespace
XmlNode jobNode = xmlDocument.CreateNode(XmlNodeType.Element, "job", null);
jobNode.InnerText = "Software developer";
employeeNode.AppendChild(jobNode);
//Here we select the first element with the name specified by variable parent and
//append the newly created child to it.
xmlDocument.SelectSingleNode("//" + parent).AppendChild(employeeNode);
//Here we save changes to the XML tree permanently.
xmlDocument.Save(filePathName);
//Here we retun some information about the file.
return GetFileInfo(filePathName);
}
示例6: Main
internal static void Main()
{
StreamReader textReader = new StreamReader("../../Person.txt");
XmlDocument xmlDocument = new XmlDocument();
XmlNode persons = xmlDocument.CreateNode(XmlNodeType.Element, "persons", string.Empty);
using (textReader)
{
while (!textReader.EndOfStream)
{
XmlNode person = xmlDocument.CreateNode(XmlNodeType.Element, "person", string.Empty);
XmlNode personName = xmlDocument.CreateNode(XmlNodeType.Element, "name", string.Empty);
XmlNode personAddres = xmlDocument.CreateNode(XmlNodeType.Element, "address", string.Empty);
XmlNode personPhone = xmlDocument.CreateNode(XmlNodeType.Element, "phone", string.Empty);
personName.InnerText = textReader.ReadLine();
personPhone.InnerText = textReader.ReadLine();
personAddres.InnerText = textReader.ReadLine();
person.AppendChild(personName);
person.AppendChild(personAddres);
person.AppendChild(personPhone);
persons.AppendChild(person);
}
}
xmlDocument.AppendChild(persons);
xmlDocument.Save("../../saved.xml");
Console.WriteLine("See results in saved.xml");
}
示例7: LoadData
public void LoadData()
{
lock (this)
{
doc = new XmlDocument();
if (File.Exists(fileName))
{
XmlTextReader reader = new XmlTextReader(fileName);
reader.WhitespaceHandling = WhitespaceHandling.None;
doc.Load(reader);
reader.Close();
}
else
{
createdFile = true;
rootNode = doc.CreateNode(XmlNodeType.Element, "Root", String.Empty);
doc.AppendChild(rootNode);
configNode = doc.CreateNode(XmlNodeType.Element, "Config", String.Empty);
rootNode.AppendChild(configNode);
}
LoadDataToClass();
if (createdFile)
{
Commit();
}
}
}
示例8: Yandex
private XmlNode Yandex()
{
if (DateTime.Now >= _cTemplate.dtNext)
{
int nBuild;
XmlNode cResult;
XmlNode[] aItems;
XmlDocument cXmlDocument = new XmlDocument();
cXmlDocument.LoadXml((new System.Net.WebClient() { Encoding = Encoding.UTF8 }).DownloadString("http://news.yandex.ru/index.rss"));
nBuild = cXmlDocument.NodeGet("rss/channel/lastBuildDate").InnerText.GetHashCode();
if (_cTemplate.nBuild != nBuild)
{
aItems = cXmlDocument.NodesGet("rss/channel/item", false);
if (null != aItems)
{
_cTemplate.nBuild = nBuild;
cXmlDocument = new XmlDocument();
cResult = cXmlDocument.CreateNode(XmlNodeType.Element, "result", null);
XmlNode cXNItem;
foreach (string sItem in aItems.Select(o => o.NodeGet("title").InnerText).ToArray())
{
cXNItem = cXmlDocument.CreateNode(XmlNodeType.Element, "item", null);
cXNItem.InnerText = sItem.StripTags() + ". ";
cResult.AppendChild(cXNItem);
}
_cTemplate.cValue = cResult;
_cTemplate.dt = DateTime.Now;
}
else
(new Logger()).WriteWarning("can't get any news from rss");
}
}
return _cTemplate.cValue;
}
示例9: LoadStaticConfiguration
protected override void LoadStaticConfiguration()
{
base.LoadStaticConfiguration();
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
string filename = config.FilePath;
database0 = database1 = "test";
XmlDocument configDoc = new XmlDocument();
configDoc.PreserveWhitespace = true;
configDoc.Load(filename);
XmlElement configNode = configDoc["configuration"];
configNode.RemoveAll();
XmlElement systemData = (XmlElement)configDoc.CreateNode(XmlNodeType.Element, "system.data", "");
XmlElement dbFactories = (XmlElement)configDoc.CreateNode(XmlNodeType.Element, "DbProviderFactories", "");
XmlElement provider = (XmlElement)configDoc.CreateNode(XmlNodeType.Element, "add", "");
provider.SetAttribute("name", "MySQL Data Provider");
provider.SetAttribute("description", ".Net Framework Data Provider for MySQL");
provider.SetAttribute("invariant", "MySql.Data.MySqlClient");
string fullname = String.Format("MySql.Data.MySqlClient.MySqlClientFactory, {0}",
typeof(MySqlConnection).Assembly.FullName);
provider.SetAttribute("type", fullname);
dbFactories.AppendChild(provider);
systemData.AppendChild(dbFactories);
configNode.AppendChild(systemData);
configDoc.Save(filename);
ConfigurationManager.RefreshSection("system.data");
}
示例10: XmlSecurityRatings
public XmlSecurityRatings()
{
_document = new XmlDocument();
/// _securityRatings = _document.CreateNode(XmlNodeType.Element, "SecurityRatings", XmlSecurityRatings._securityNs);
_securityRatings = _document.CreateNode(XmlNodeType.Element, "SecurityRatings", null);
_document.AppendChild(_securityRatings);
_highSecurity = _document.CreateNode(XmlNodeType.Element, "High", null);
_securityRatings.AppendChild(_highSecurity);
appendAttribute(_highSecurity, @"title", @"HIGH RISK");
appendAttribute(_highSecurity, @"comment", @"This document contains high risk elements");
appendAttribute(_highSecurity, @"color", @"#B14343");
appendAttribute(_highSecurity, @"include-in-summary", @"yes");
appendAttribute(_highSecurity, @"hiddendata", @"This document contains high risk hidden data");
appendAttribute(_highSecurity, @"contentpolicy", @"This document contains high risk content policy violations");
_mediumSecurity = _document.CreateNode(XmlNodeType.Element, "Medium", null);
_securityRatings.AppendChild(_mediumSecurity);
appendAttribute(_mediumSecurity, @"title", @"MEDIUM RISK");
appendAttribute(_mediumSecurity, @"comment", @"This document contains medium risk elements");
appendAttribute(_mediumSecurity, @"color", @"#F0C060");
appendAttribute(_mediumSecurity, @"include-in-summary", @"yes");
appendAttribute(_mediumSecurity, @"hiddendata", @"This document contains medium risk hidden data");
appendAttribute(_mediumSecurity, @"contentpolicy", @"This document contains medium risk content policy violations");
_lowSecurity = _document.CreateNode(XmlNodeType.Element, "Low", null);
_securityRatings.AppendChild(_lowSecurity);
appendAttribute(_lowSecurity, @"title", @"LOW RISK");
appendAttribute(_lowSecurity, @"comment", @"This document contains normal elements");
appendAttribute(_lowSecurity, @"color", @"#4E7C49");
appendAttribute(_lowSecurity, @"include-in-summary", @"no");
appendAttribute(_lowSecurity, @"hiddendata", @"This document contains low risk hidden data");
appendAttribute(_lowSecurity, @"contentpolicy", @"This document contains low risk content policy violations");
}
示例11: CreateXMLDocument
public static XmlDocument CreateXMLDocument()
{
XmlDocument doc = new XmlDocument();
XmlNode docNode = doc.CreateXmlDeclaration("1.0", null, null);
doc.AppendChild(docNode);
XmlNode configurationNode = doc.CreateElement("Configuration");
doc.AppendChild(configurationNode);
XmlNode hostNode = doc.CreateNode(XmlNodeType.Element, "host", "");
hostNode.InnerText = "https://testserver.datacash.com/Transaction";
XmlNode timeoutNode = doc.CreateNode(XmlNodeType.Element, "timeout", "");
timeoutNode.InnerText = "500";
XmlNode proxyNode = doc.CreateNode(XmlNodeType.Element, "proxy", "");
proxyNode.InnerText = "http://bloxx.dfguk.com:8080";
XmlNode logfileNode = doc.CreateNode(XmlNodeType.Element, "logfile", "");
logfileNode.InnerText = @"C:\Inetpub\wwwroot\WSDataCash\log.txt";
XmlNode loggingNode = doc.CreateNode(XmlNodeType.Element, "logging", "");
loggingNode.InnerText = "1";
configurationNode.AppendChild(hostNode);
configurationNode.AppendChild(timeoutNode);
configurationNode.AppendChild(proxyNode);
configurationNode.AppendChild(logfileNode);
configurationNode.AppendChild(loggingNode);
return doc;
}
示例12: ToXml
public XmlElement ToXml(XmlDocument document)
{
if (string.IsNullOrEmpty(program)) throw new InvalidOperationException("There must be a program node.");
XmlElement alertNode = document.CreateElement("idmef:OverflowAlert", "http://iana.org/idmef");
XmlElement subNode = document.CreateElement("idmef:program", "http://iana.org/idmef");
XmlNode subNodeText = document
.CreateNode(XmlNodeType.Text, "idmef", "program", "http://iana.org/idmef");
subNodeText.Value = program;
subNode.AppendChild(subNodeText);
alertNode.AppendChild(subNode);
if (size != null)
{
subNode = document.CreateElement("idmef:size", "http://iana.org/idmef");
subNodeText = document.CreateNode(XmlNodeType.Text, "idmef", "size", "http://iana.org/idmef");
subNodeText.Value = size.ToString();
subNode.AppendChild(subNodeText);
alertNode.AppendChild(subNode);
}
if ((buffer != null) && (buffer.Length > 0))
{
subNode = document.CreateElement("idmef:buffer", "http://iana.org/idmef");
subNodeText = document.CreateNode(XmlNodeType.Text, "idmef", "buffer", "http://iana.org/idmef");
subNodeText.Value = Convert.ToBase64String(buffer);
subNode.AppendChild(subNodeText);
alertNode.AppendChild(subNode);
}
return alertNode;
}
示例13: AddAttachmentPlaceHolder
public void AddAttachmentPlaceHolder(string actualPath, string placeholderPath)
{
var placeholderDocument = new XmlDocument();
placeholderDocument.CreateXmlDeclaration("1.0", "utf-16", "yes");
XmlNode rootNode = placeholderDocument.CreateNode(XmlNodeType.Element, "ManagedAttachment", string.Empty);
XmlNode actualPathNode = placeholderDocument.CreateNode(XmlNodeType.Element, "ActualPath", string.Empty);
XmlNode placeholderNode = placeholderDocument.CreateNode(XmlNodeType.Element, "PlaceholderPath",
string.Empty);
actualPathNode.InnerText = actualPath;
placeholderNode.InnerText = placeholderPath;
rootNode.AppendChild(actualPathNode);
rootNode.AppendChild(placeholderNode);
placeholderDocument.AppendChild(rootNode);
using (var ms = new MemoryStream())
{
ms.Position = 0;
placeholderDocument.Save(ms);
ms.Flush();
ms.Position = 0;
var sr = new StreamReader(ms);
string xml = sr.ReadToEnd();
string filecontents = LargeAttachmentHelper.FileTag + xml;
File.WriteAllText(placeholderPath, filecontents, Encoding.Unicode);
}
}
示例14: CreatingFile
public string CreatingFile(XMLMovieProperties objMovie)
{
try
{
if (objMovie == null) return null;
BlobStorageService _blobStorageService = new BlobStorageService();
XmlDocument documnet = new XmlDocument();
string fileName = "MovieList-" + objMovie.Month.Substring(0, 3) + "-" + objMovie.Year.ToString() + ".xml";
string existFileContent = _blobStorageService.GetUploadeXMLFileContent(BlobStorageService.Blob_XMLFileContainer, fileName);
if (!string.IsNullOrEmpty(existFileContent))
{
documnet.LoadXml(existFileContent);
var oldMonth = documnet.SelectSingleNode("Movies/Month[@name='" + objMovie.Month + "']");
var oldMovie = oldMonth.SelectSingleNode("Movie[@name='" + objMovie.MovieName + "']");
if (oldMovie == null)
oldMonth.AppendChild(AddMovieNode(documnet, objMovie));
else
{
oldMonth.RemoveChild(oldMovie);
oldMonth.AppendChild(AddMovieNode(documnet, objMovie));
}
}
else
{
XmlNode root = documnet.CreateNode(XmlNodeType.Element, "Movies", "");
XmlAttribute movieYear = documnet.CreateAttribute("year");
movieYear.Value = objMovie.Year.ToString();
root.Attributes.Append(movieYear);
XmlNode month = documnet.CreateNode(XmlNodeType.Element, "Month", "");
XmlAttribute monthName = documnet.CreateAttribute("name");
monthName.Value = objMovie.Month.ToString();
month.Attributes.Append(monthName);
month.AppendChild(AddMovieNode(documnet, objMovie));
root.AppendChild(month);
documnet.AppendChild(root);
}
_blobStorageService.UploadXMLFileOnBlob(BlobStorageService.Blob_XMLFileContainer, fileName, documnet.OuterXml);
return documnet.OuterXml;
//return fileName;
}
catch (Exception ex)
{
Console.Write(ex.Message);
return "";
}
}
示例15: ProcessInputKeyFile
public void ProcessInputKeyFile(string inputPath, string outputPath, string pass,X509Certificate2 xcert,bool flag,string oneTimePassword )
{
string strKey = string.Format("//{0}/{1}", CollectionIDTag, KeyTag);
string strID = string.Format("//{0}/{1}", CollectionIDTag, iFolderIDTag);
string decKey;
byte[] decKeyByteArray;
rsadec = xcert.PrivateKey as RSACryptoServiceProvider;
try
{
string inKeyPath = Path.GetFullPath(inputPath);
string outKeyPath = Path.GetFullPath(outputPath);
XmlDocument encFile = new XmlDocument();
encFile.Load(inKeyPath);
XmlNodeList keyNodeList, idNodeList;
XmlElement root = encFile.DocumentElement;
keyNodeList = root.SelectNodes(strKey);
idNodeList = root.SelectNodes(strID);
System.Xml.XmlDocument document = new XmlDocument();
XmlDeclaration xmlDeclaration = document.CreateXmlDeclaration("1.0", "utf-8", null);
document.InsertBefore(xmlDeclaration, document.DocumentElement);
XmlElement title = document.CreateElement(titleTag);
document.AppendChild(title);
int i = 0;
foreach (XmlNode idNode in idNodeList)
{
if (idNode.InnerText == null || idNode.InnerText == String.Empty)
continue;
Console.WriteLine(idNode.InnerText);
XmlNode newNode = document.CreateNode("element", CollectionIDTag, "");
newNode.InnerText = "";
document.DocumentElement.AppendChild(newNode);
XmlNode innerNode = document.CreateNode("element", iFolderIDTag, "");
innerNode.InnerText = idNode.InnerText;
newNode.AppendChild(innerNode);
{
XmlNode keyNode = keyNodeList[i++];
Console.WriteLine(decKey = keyNode.InnerText);
decKeyByteArray = Convert.FromBase64String(decKey);
XmlNode newElem2 = document.CreateNode("element", KeyTag, "");
if (decKey == null || decKey == String.Empty)
continue;
if (flag == true)
newElem2.InnerText = DecodeMessage(decKeyByteArray, oneTimePassword);
else
newElem2.InnerText = DecodeMessage(decKeyByteArray);
newNode.AppendChild(newElem2);
}
}
if (File.Exists(outKeyPath))
File.Delete(outKeyPath);
document.Save(outKeyPath);
}
catch (Exception e)
{
Console.WriteLine("Exception while processing" + e.Message + e.StackTrace);
}
}