本文整理匯總了C#中System.Xml.XmlDocument.CreateElement方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlDocument.CreateElement方法的具體用法?C# XmlDocument.CreateElement怎麽用?C# XmlDocument.CreateElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.CreateElement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SaveNode
protected override void SaveNode(XmlDocument xmlDoc, XmlElement nodeElement, SaveContext context)
{
Controller.SaveNode(xmlDoc, nodeElement, context);
var outEl = xmlDoc.CreateElement("Name");
outEl.SetAttribute("value", NickName);
nodeElement.AppendChild(outEl);
outEl = xmlDoc.CreateElement("Description");
outEl.SetAttribute("value", Description);
nodeElement.AppendChild(outEl);
outEl = xmlDoc.CreateElement("Inputs");
foreach (string input in InPortData.Select(x => x.NickName))
{
XmlElement inputEl = xmlDoc.CreateElement("Input");
inputEl.SetAttribute("value", input);
outEl.AppendChild(inputEl);
}
nodeElement.AppendChild(outEl);
outEl = xmlDoc.CreateElement("Outputs");
foreach (string output in OutPortData.Select(x => x.NickName))
{
XmlElement outputEl = xmlDoc.CreateElement("Output");
outputEl.SetAttribute("value", output);
outEl.AppendChild(outputEl);
}
nodeElement.AppendChild(outEl);
}
示例2: OverWriting
private bool OverWriting() {
//private async Task<bool> OverWriting() {
if (ListingQueue.Any()) {
XmlDocument xmlDoc;
XmlElement xmlEle;
XmlNode newNode;
xmlDoc = new XmlDocument();
xmlDoc.Load("ImageData.xml"); // XML문서 로딩
newNode = xmlDoc.SelectSingleNode("Images"); // 추가할 부모 Node 찾기
xmlEle = xmlDoc.CreateElement("Image");
newNode.AppendChild(xmlEle);
newNode = newNode.LastChild;
xmlEle = xmlDoc.CreateElement("ImagePath"); // 추가할 Node 생성
xmlEle.InnerText = ListingQueue.Peek();
ListingQueue.Dequeue();
newNode.AppendChild(xmlEle); // 위에서 찾은 부모 Node에 자식 노드로 추가..
xmlDoc.Save("ImageData.xml"); // XML문서 저장..
xmlDoc = null;
return true;
}
return false;
}
示例3: GetXML
private string GetXML()
{
XmlDocument document = new XmlDocument();
XmlElement RazaoNode = document.CreateElement("Razao");
RazaoNode.InnerText = Razao;
XmlElement ValoresNode = document.CreateElement("Valores");
XmlElement ValorNode = document.CreateElement("Valor");
XmlAttribute moeda = document.CreateAttribute("moeda");
moeda.Value = "BRL";
ValorNode.Attributes.Append(moeda);
ValorNode.InnerText = String.Format("{0:0.00}", Valor).Replace(',','.');
ValoresNode.AppendChild(ValorNode);
XmlNode EnviarInstrucao = document.CreateElement("EnviarInstrucao");
XmlNode InstrucaoUnica = EnviarInstrucao.AppendChild(document.CreateNode(XmlNodeType.Element, "InstrucaoUnica", ""));
InstrucaoUnica.AppendChild(RazaoNode);
InstrucaoUnica.AppendChild(ValoresNode);
return EnviarInstrucao.OuterXml;
}
示例4: GetHttpRuntime
public static XmlElement GetHttpRuntime(XmlDocument configuration, bool createIfMissing = false)
{
var systemWeb = configuration.SelectSingleElement("/configuration/system.web");
if (systemWeb == null)
{
if (!createIfMissing)
{
return null;
}
systemWeb = configuration.CreateElement("system.web");
configuration.DocumentElement.AppendChild(systemWeb);
}
var httpRuntime = systemWeb.SelectSingleElement("httpRuntime");
if (httpRuntime != null)
{
return httpRuntime;
}
if (!createIfMissing)
{
return null;
}
httpRuntime = configuration.CreateElement("httpRuntime");
systemWeb.AppendChild(httpRuntime);
return httpRuntime;
}
示例5: Save
public void Save(string path)
{
this.time = DateTime.Now;
if (!File.Exists(path))
{
XmlWriter writer = XmlWriter.Create(path);
writer.WriteStartElement("head");
writer.WriteFullEndElement();
writer.Close();
}
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode root = doc.DocumentElement;
XmlElement newOrder = doc.CreateElement("OrderId");
XmlElement newUser = doc.CreateElement("UserId");
XmlElement newTime = doc.CreateElement("Time");
XmlText orderId = doc.CreateTextNode(this.IdOrder.ToString());
XmlText userId = doc.CreateTextNode(this.IdUser.ToString());
XmlText checkTime = doc.CreateTextNode(this.time.ToString("o"));
newOrder.AppendChild(orderId);
newUser.AppendChild(userId);
newTime.AppendChild(checkTime);
root.InsertAfter(newOrder, root.LastChild);
root.InsertAfter(newUser, root.LastChild);
root.InsertAfter(newTime, root.LastChild);
doc.Save(path);
}
示例6: 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;
}
示例7: ToText
public override string ToText(Subtitle subtitle, string title)
{
string xmlStructure = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + Environment.NewLine + "<Subtitle/>";
XmlDocument xml = new XmlDocument();
xml.LoadXml(xmlStructure);
foreach (Paragraph p in subtitle.Paragraphs)
{
XmlNode paragraph = xml.CreateElement("Paragraph");
XmlNode number = xml.CreateElement("Number");
number.InnerText = p.Number.ToString();
paragraph.AppendChild(number);
XmlNode start = xml.CreateElement("StartMilliseconds");
start.InnerText = p.StartTime.TotalMilliseconds.ToString(CultureInfo.InvariantCulture);
paragraph.AppendChild(start);
XmlNode end = xml.CreateElement("EndMilliseconds");
end.InnerText = p.EndTime.TotalMilliseconds.ToString(CultureInfo.InvariantCulture);
paragraph.AppendChild(end);
XmlNode text = xml.CreateElement("Text");
text.InnerText = HtmlUtil.RemoveHtmlTags(p.Text);
paragraph.AppendChild(text);
xml.DocumentElement.AppendChild(paragraph);
}
return ToUtf8XmlString(xml);
}
示例8: tokenize
/// <summary>
/// Implements the following function
/// node-set tokenize(string, string)
/// </summary>
/// <param name="str"></param>
/// <param name="delimiters"></param>
/// <returns>This function breaks the input string into a sequence of strings,
/// treating any character in the list of delimiters as a separator.
/// The separators themselves are not returned.
/// The tokens are returned as a set of 'token' elements.</returns>
public XPathNodeIterator tokenize(string str, string delimiters)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<tokens/>");
if (delimiters == String.Empty)
{
foreach (char c in str)
{
XmlElement elem = doc.CreateElement("token");
elem.InnerText = c.ToString();
doc.DocumentElement.AppendChild(elem);
}
}
else
{
foreach (string token in str.Split(delimiters.ToCharArray()))
{
XmlElement elem = doc.CreateElement("token");
elem.InnerText = token;
doc.DocumentElement.AppendChild(elem);
}
}
return doc.CreateNavigator().Select("//token");
}
示例9: Save
/// <summary>
/// Saves the contents of this instance to the defined config file.
/// </summary>
/// <param name="force">If false, will only save if the flag indicates that changes have been made. If true, always saves.</param>
public void Save( bool force = false ) {
if( force || outOfDate ) {
Type t = this.GetType();
PropertyInfo[] properties = t.GetProperties();
XmlDocument doc = new XmlDocument();
XmlElement config = doc.CreateElement( "config" );
lock( threadLock ) {
foreach( PropertyInfo pi in properties ) {
object val = pi.GetValue( this, null );
if( val != null ) {
XmlElement element = doc.CreateElement( pi.Name );
element.InnerText = val.ToString();
config.AppendChild( element );
}
}
}
doc.AppendChild( config );
try {
doc.Save( FilePath );
} catch( IOException ) {
}
outOfDate = false;
}
}
示例10: addData
public void addData(string XmlFilePath,StringBuilder str)
{
XmlDocument document = new XmlDocument();
document.Load(XmlFilePath);
XmlNode element = document.CreateElement("info");
document.DocumentElement.AppendChild(element);
XmlNode title = document.CreateElement("title");
title.InnerText = XmlFilePath;
element.AppendChild(title);
XmlNode chapter = document.CreateElement("chapter");
document.DocumentElement.AppendChild(chapter); // указываем родителя
XmlNode para = document.CreateElement("para");
para.InnerText = str.ToString();
chapter.AppendChild(para);
document.Save(XmlFilePath);
// Console.WriteLine("Data have been added to xml!");
// Console.ReadKey();
// Console.WriteLine(XmlToJSON(document));
}
示例11: Subscribe
public string Subscribe(string deliveryUrl, string eventType)
{
string subscriptionId = Guid.NewGuid().ToString();
XmlDocument subscriptionStore = new XmlDocument();
subscriptionStore.Load(subscriptionStorePath);
// Add a new subscription
XmlNode newSubNode = subscriptionStore.CreateElement("Subscription");
XmlNode subscriptionIdStart = subscriptionStore.CreateElement("SubscriptionID");
subscriptionIdStart.InnerText = subscriptionId;
newSubNode.AppendChild(subscriptionIdStart);
XmlNode deliveryAddressStart = subscriptionStore.CreateElement("DeliveryAddress");
deliveryAddressStart.InnerText = deliveryUrl;
newSubNode.AppendChild(deliveryAddressStart);
XmlNode eventTypeStart = subscriptionStore.CreateElement("EventType");
eventTypeStart.InnerText = eventType;
newSubNode.AppendChild(eventTypeStart);
subscriptionStore.DocumentElement.AppendChild(newSubNode);
subscriptionStore.Save(subscriptionStorePath);
return subscriptionId;
}
示例12: saveGesture
//Saves given Unistroke to file as a new gesture with name specified
public static void saveGesture(ref SignalProcessing.Unistroke<double> u, string name)
{
XmlDocument doc = new XmlDocument();
doc.Load("gestures.xml");
XmlNodeList nl = doc.GetElementsByTagName("gesture_set");
XmlElement gesture_elem= doc.CreateElement("gesture");
XmlAttribute ident = doc.CreateAttribute("name");
ident.InnerText = name;
gesture_elem.Attributes.Append(ident);
for(int i = 0; i < u.trace.Count; i++){
XmlElement n = doc.CreateElement("point");
XmlAttribute x = doc.CreateAttribute("x");
XmlAttribute y = doc.CreateAttribute("y");
XmlAttribute z = doc.CreateAttribute("z");
x.InnerText = u[i].x.ToString();
y.InnerText = u[i].y.ToString();
z.InnerText = u[i].z.ToString();
n.Attributes.Append(x);
n.Attributes.Append(y);
n.Attributes.Append(z);
gesture_elem.AppendChild(n);
}
nl[0].AppendChild(gesture_elem);
doc.Save("gestures.xml");
}
示例13: GenerateStrings
private void GenerateStrings(string inputPath, string outputFile)
{
XElement rootElement = XElement.Load(inputPath);
IEnumerable<Tuple<string, string>> items = from dataElement in rootElement.Descendants("data")
let key = dataElement.Attribute("name").Value
let valueElement = dataElement.Element("value")
where valueElement != null
let value = valueElement.Value
select new Tuple<string, string>(key, value);
XmlDocument document = new XmlDocument();
document.AppendChild(document.CreateXmlDeclaration("1.0", "utf-8", null));
XmlNode rootNode = document.CreateElement("resources");
document.AppendChild(rootNode);
foreach (var pair in items)
{
XmlNode elementNode = document.CreateElement("string");
elementNode.InnerText = processValue(pair.Item2);
XmlAttribute attributeName = document.CreateAttribute("name");
attributeName.Value = processKey(pair.Item1);
// ReSharper disable once PossibleNullReferenceException
elementNode.Attributes.Append(attributeName);
rootNode.AppendChild(elementNode);
}
document.Save(outputFile);
}
示例14: GetMacro
public XmlNode GetMacro(int Id, string Login, string Password)
{
if (ValidateCredentials(Login, Password)
&& UserHasAppAccess(DefaultApps.developer.ToString(), Login))
{
var xmlDoc = new XmlDocument();
var macro = xmlDoc.CreateElement("macro");
var m = new cms.businesslogic.macro.Macro(Id);
macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "id", m.Id.ToString()));
macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "refreshRate", m.RefreshRate.ToString()));
macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "useInEditor", m.UseInEditor.ToString()));
macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "alias", m.Alias));
macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "name", m.Name));
macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "assembly", m.Assembly));
macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "type", m.Type));
macro.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "xslt", m.Xslt));
var properties = xmlDoc.CreateElement("properties");
foreach (var mp in m.Properties)
{
var pXml = xmlDoc.CreateElement("property");
pXml.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "alias", mp.Alias));
pXml.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "name", mp.Name));
pXml.Attributes.Append(XmlHelper.AddAttribute(xmlDoc, "public", mp.Public.ToString()));
properties.AppendChild(pXml);
}
macro.AppendChild(properties);
return macro;
}
return null;
}
示例15: Serialize
/// <summary>
/// Serializes the specified play list items.
/// </summary>
/// <param name="items">The play list.</param>
/// <returns>The serielized play list as xml document.</returns>
public XmlDocument Serialize(IEnumerable<ListViewItem> items)
{
var doc = new XmlDocument();
XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "utf-8", "yes");
doc.AppendChild(declaration);
XmlElement root = doc.CreateElement("items");
doc.AppendChild(root);
foreach (ListViewItem item in items)
{
XmlElement element = doc.CreateElement("item");
element.InnerText = item.Text;
XmlAttribute startTime = doc.CreateAttribute("start");
startTime.InnerText = item.SubItems[1].Text;
element.Attributes.Append(startTime);
XmlAttribute endTime = doc.CreateAttribute("end");
endTime.InnerText = item.SubItems[2].Text;
element.Attributes.Append(endTime);
XmlAttribute duration = doc.CreateAttribute("duration");
duration.InnerText = item.SubItems[3].Text;
element.Attributes.Append(duration);
root.AppendChild(element);
}
return doc;
}