本文整理匯總了C#中System.Xml.XmlDocument.AppendChild方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlDocument.AppendChild方法的具體用法?C# XmlDocument.AppendChild怎麽用?C# XmlDocument.AppendChild使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.AppendChild方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: XmlCreateReports
/// <summary>
/// Creates XML reports and save them as a XML file
/// </summary>
public static void XmlCreateReports(ICollection<DtoStadiumReport> stadiumReports)
{
var stadiumReport = stadiumReports;
XmlDocument xmlReport = new XmlDocument();
XmlDeclaration xmlDeclaration = xmlReport.CreateXmlDeclaration(Version, Encoding, null);
XmlElement root = xmlReport.CreateElement(RootName);
foreach (var stadium in stadiumReport)
{
XmlElement stadiumElement = xmlReport.CreateElement("stadium");
stadiumElement.SetAttribute("id", stadium.Id.ToString());
XmlElement stadiumName = xmlReport.CreateElement("name");
stadiumName.InnerText = stadium.Name;
XmlElement stadiumCapacity = xmlReport.CreateElement("capacity");
stadiumCapacity.InnerText = stadium.Capacity.ToString();
XmlElement stadiumTownName = xmlReport.CreateElement("town");
stadiumTownName.InnerText = stadium.TownName;
stadiumElement.AppendChild(stadiumName);
stadiumElement.AppendChild(stadiumCapacity);
stadiumElement.AppendChild(stadiumTownName);
root.AppendChild(stadiumElement);
}
xmlReport.AppendChild(xmlDeclaration);
xmlReport.AppendChild(root);
xmlReport.Save(SaveFilePath+FileName);
Process.Start(SaveFilePath);
}
示例2: btn_OK_Click
private void btn_OK_Click(object sender, EventArgs e)
{
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
xmlDoc.AppendChild(docNode);
XmlNode version = xmlDoc.CreateElement("version");
xmlDoc.AppendChild(version);
XmlNode sbtNode = xmlDoc.CreateElement("SBT");
XmlAttribute sbtAttribute = xmlDoc.CreateAttribute("Path");
sbtAttribute.Value = textBox1.Text;
sbtNode.Attributes.Append(sbtAttribute);
version.AppendChild(sbtNode);
XmlNode garenaNode = xmlDoc.CreateElement("Garena");
XmlAttribute garenaAttribute = xmlDoc.CreateAttribute("Path");
garenaAttribute.Value = textBox2.Text;
garenaNode.Attributes.Append(garenaAttribute);
version.AppendChild(garenaNode);
XmlNode superNode = xmlDoc.CreateElement("Super");
XmlAttribute superAttribute = xmlDoc.CreateAttribute("Path");
superAttribute.Value = textBox3.Text;
superNode.Attributes.Append(superAttribute);
version.AppendChild(superNode);
xmlDoc.Save("path");
this.Close();
}
示例3: InvokeResponse
public string InvokeResponse(string funcName, List<UPnPArg> args)
{
XmlDocument doc = new XmlDocument();
XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
doc.AppendChild(dec);
XmlElement env = doc.CreateElement("s", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/");
doc.AppendChild(env);
env.SetAttribute("encodingStyle", "http://schemas.xmlsoap.org/soap/envelope/", "http://schemas.xmlsoap.org/soap/encoding/");
XmlElement body = doc.CreateElement("Body", "http://schemas.xmlsoap.org/soap/envelope/");
body.Prefix = "s";
env.AppendChild(body);
XmlElement func = doc.CreateElement("u", funcName + "Response", "urn:schemas-upnp-org:service:AVTransport:1");
body.AppendChild(func);
func.SetAttribute("xmlns:u", "urn:schemas-upnp-org:service:AVTransport:1");
if (args != null)
{
foreach (UPnPArg s in args)
{
XmlElement f = doc.CreateElement(s.ArgName);
func.AppendChild(f);
f.InnerText = s.ArgVal;
}
}
//Saved for debugging:
doc.Save(@"InvokeResponse.xml");
string msg = AppendHead(doc.OuterXml);
return msg;
}
示例4: ConvertFromPHP
public static string ConvertFromPHP(string sPHP)
{
XmlDocument xml = new XmlDocument();
xml.AppendChild(xml.CreateProcessingInstruction("xml" , "version=\"1.0\" encoding=\"UTF-8\""));
xml.AppendChild(xml.CreateElement("USER_PREFERENCE"));
try
{
byte[] abyPHP = Convert.FromBase64String(sPHP);
StringBuilder sb = new StringBuilder();
foreach(char by in abyPHP)
sb.Append(by);
MemoryStream mem = new MemoryStream(abyPHP);
string sSize = String.Empty;
int nChar = mem.ReadByte();
while ( nChar != -1 )
{
char ch = Convert.ToChar(nChar);
if ( ch == 'a' )
PHPArray(xml, xml.DocumentElement, mem);
else if ( ch == 's' )
PHPString(mem);
else if ( ch == 'i' )
PHPInteger(mem);
nChar = mem.ReadByte();
}
}
catch(Exception ex)
{
SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
}
return xml.OuterXml;
}
示例5: CreateXml
public void CreateXml(string xmlPath, string xmlName, string[] value, string[] xmlElementNode)
{
try
{
string str = inType.ToString();
if (str.Length < 5)
{
return;
}
string rootName = str.Substring(str.Length - 5, 4);
XmlDocument doc = new XmlDocument();
XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(dec);
XmlElement root = doc.CreateElement(rootName);
doc.AppendChild(root);
XmlNode childElement = doc.CreateElement(str);
for (int i = 0; i < xmlElementNode.Length; i++)
{
XmlElement xe = doc.CreateElement(xmlElementNode[i]);
xe.InnerText = value[i];
childElement.AppendChild(xe);
}
root.AppendChild(childElement);
doc.Save(string.Concat(@"", xmlPath, xmlName));
}
catch (Exception e)
{
throw e;
}
}
示例6: Read
public XmlDocument Read(out string title)
{
var result = new XmlDocument();
var pkgDoc = new XmlDocument();
pkgDoc.Load(_path);
string folderPath;
result.AppendChild(result.CreateElement("AML"));
XmlElement child;
var scripts = new List<InstallItem>();
title = null;
foreach (var pkg in pkgDoc.DocumentElement.Elements("package"))
{
title = pkg.Attribute("name", "");
folderPath = pkg.Attribute("path");
if (folderPath == ".\\") folderPath = InnovatorPackage.CleanFileName(title).Replace('.', '\\');
foreach (var file in Directory.GetFiles(Path.Combine(Path.GetDirectoryName(_path), folderPath), "*.xml", SearchOption.AllDirectories))
{
child = result.CreateElement("AML");
child.InnerXml = System.IO.File.ReadAllText(file);
foreach (var item in child.Element("AML").Elements("Item"))
{
result.AppendChild(item);
}
}
}
return result;
}
示例7: BuildTreeNodes
public static TreeNodeCollection BuildTreeNodes(bool refreshSiteMap)
{
XmlDocument map = null;
XmlElement root = null;
XmlElement examplesNode = null;
if (refreshSiteMap)
{
map = new XmlDocument();
XmlDeclaration dec = map.CreateXmlDeclaration("1.0", "utf-8", null);
map.AppendChild(dec);
root = map.CreateElement("siteMap");
root.SetAttribute("xmlns", "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0");
map.AppendChild(root);
examplesNode = map.CreateElement("siteMapNode");
examplesNode.SetAttribute("title", "Examples");
root.AppendChild(examplesNode);
}
string path = HttpContext.Current.Server.MapPath("~/Examples/");
TreeNodeCollection result = BuildTreeLevel(new DirectoryInfo(path), 1, 3, examplesNode);
if (root != null && root.ChildNodes.Count > 0)
{
map.Save(HttpContext.Current.Server.MapPath("Web.sitemap"));
}
return result;
}
示例8: 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;
}
示例9: Export
public void Export(string fileOut)
{
XmlDocument doc = new XmlDocument();
doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null));
XmlElement root = doc.CreateElement("DungeonList");
for (int i = 0; i < dl.Length; i++)
{
XmlElement b = doc.CreateElement("Block");
XmlElement title = doc.CreateElement("Title");
title.InnerText = Helper.Format(dl[i].title, 6);
b.AppendChild(title);
for (int j = 0; j < dl[i].entries.Length; j++)
{
XmlElement msg = doc.CreateElement("Message");
msg.InnerText = Helper.Format(dl[i].entries[j].text, 8);
msg.SetAttribute("Script", dl[i].entries[j].script_name);
b.AppendChild(msg);
}
root.AppendChild(b);
}
doc.AppendChild(root);
root = null;
doc.Save(fileOut);
doc = null;
}
示例10: pullData
public void pullData()
{
dataPulled = true;
if (elements.Count != 0)
{
writeData();
}
XmlDocument myXmlDocument = new XmlDocument();
try
{
myXmlDocument.Load(fileLoc);
}
catch (XmlException exception)
{
//file not setup
Console.WriteLine("Exception Reading XML: " + exception.ToString());
XmlDeclaration dec = myXmlDocument.CreateXmlDeclaration("1.0", null, null);
myXmlDocument.AppendChild(dec);
myXmlDocument.AppendChild(myXmlDocument.CreateElement("myData"));
}
XmlNodeList currentLetters = myXmlDocument.DocumentElement.SelectNodes("DataElement");
foreach (XmlElement element in currentLetters)
{
elements.Add( getDataElement(element));
}
myXmlDocument.Save(fileLoc);
}
示例11: analizuj
public Boolean analizuj()
{
if (sciezka == "")
{
return true;
}
XmlDocument tempXML = new XmlDocument();
XmlDeclaration dec = tempXML.CreateXmlDeclaration("1.0", "UTF-8", null);
tempXML.AppendChild(dec);
XmlElement main = tempXML.CreateElement("body");
XmlElement sc = tempXML.CreateElement("schemat");
XmlText wartosc = tempXML.CreateTextNode(schemat);
sc.AppendChild(wartosc);
main.AppendChild(sc);
generuj_elementy(sciezka, main, tempXML);
tempXML.AppendChild(main);
String p = sciezka + "\\" + "temp.xml";
String q = sciezka + "\\" + "struktura_logiczna.xml";
tempXML.Save(p);
if (System.IO.File.ReadAllText(p) == System.IO.File.ReadAllText(q))
{
System.IO.File.Delete(p);
return true;
}
else
{
System.IO.File.Delete(p);
return false;
}
}
示例12: GetXMLString
public string GetXMLString()
{
XmlDocument xmlDocument = new XmlDocument();
XmlDeclaration xmlDeclaration = xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", null);
xmlDocument.AppendChild(xmlDeclaration);
XmlElement root = xmlDocument.CreateElement("ServiceResponse", "http://www.phonebook.com/ServiceResponse");
xmlDocument.AppendChild(root);
XmlElement status = xmlDocument.CreateElement("Status", xmlDocument.DocumentElement.NamespaceURI);
status.InnerText = m_Status.ToString();
root.AppendChild(status);
if (m_Information.Length > 0)
{
XmlElement information = xmlDocument.CreateElement("Information", xmlDocument.DocumentElement.NamespaceURI);
information.InnerText = m_Information;
root.AppendChild(information);
}
if (m_Payload.Length > 0)
{
XmlElement payload = xmlDocument.CreateElement("Payload", xmlDocument.DocumentElement.NamespaceURI);
XmlDocument payloadXmlDocument = new XmlDocument();
payloadXmlDocument.LoadXml(m_Payload);
XmlNode payloadXmlNode = xmlDocument.ImportNode(payloadXmlDocument.DocumentElement, true);
payload.AppendChild(payloadXmlNode);
root.AppendChild(payload);
}
string outputxml = xmlDocument.OuterXml;
outputxml = outputxml.Replace(" xmlns=\"\"", "");
return outputxml;
}
示例13: GetAppSettingsXml
private string GetAppSettingsXml(object config, Encoding encode)
{
BaseAttributeConfigBean c = config as BaseAttributeConfigBean;
if (c == null)
{
return string.Empty;
}
string[] keys = null;
if (!string.IsNullOrEmpty(c.GetSearchConfigKey()))
{
keys = c.GetSearchConfigKey().Split('|');
}
var doc = new XmlDocument();
doc.AppendChild(doc.CreateXmlDeclaration("1.0", encode.BodyName, null));
var root = doc.CreateElement("config");
doc.AppendChild(root);
foreach (ConfigEntity entity in c.GetEntries())
{
if (entity.CanRead)
{
if (keys == null||keys.Contains<string>(entity.Key))
{
var bel = doc.CreateElement("item");
root.AppendChild(bel);
bel.SetAttribute("name", entity.Key);
bel.SetAttribute("value", entity.Value != null ? entity.Value.ToString() : string.Empty);
}
}
}
return doc.OuterXml;
}
示例14: Main
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.AppendChild(dec);
XmlElement order = doc.CreateElement("Order");
doc.AppendChild(order);
XmlElement customerName = doc.CreateElement("CustomerName");
customerName.InnerXml = "<p>aaa</p>";
order.AppendChild(customerName);
XmlElement customerNumber = doc.CreateElement("CustomerNumber");
customerNumber.InnerText = "100001";
order.AppendChild(customerNumber);
XmlElement items = doc.CreateElement("Items");
order.AppendChild(items);
XmlElement orderItem1 = doc.CreateElement("OrderItem");
orderItem1.SetAttribute("Name", "樹");
orderItem1.SetAttribute("Count", "10");
items.AppendChild(orderItem1);
doc.Save("Order.xml");
Console.WriteLine("success");
}
示例15: button1_Click
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Equals(textBox2.Text))
{
XmlDocument xmldoc = new XmlDocument();
XmlElement xmlelem;
XmlNode xmlnode;
XmlText xmltext;
xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
xmldoc.AppendChild(xmlnode);
xmlelem = xmldoc.CreateElement("", "ROOT", "");
xmltext = xmldoc.CreateTextNode(textBox1.Text);
xmlelem.AppendChild(xmltext);
xmldoc.AppendChild(xmlelem);
xmldoc.Save(path + "\\p.xml");
this.Close();
}
else
{
MessageBox.Show("Two text do not match", "Error");
textBox1.Clear();
textBox2.Clear();
textBox1.Focus();
}
}