Add Elements XDocument - CSharp System.Xml

CSharp examples for System.Xml:XML Document

Description

Add Elements XDocument

Demo Code


using System.Windows.Forms.MessageBox;
using System.Xml.Linq;
using System.Windows.Forms;
using System.Linq;
using System.IO;//from  ww w  .  ja  v a  2  s.c  o  m
using System.Collections.Generic;
using System;

public class Main{
        public static XDocument AddElementsXDoc()
        {
            LoadXml();

            //if ((lastFolderXElements.Count() != 6)) return _mainXmlDocument;

            var id = GetLastViewId() + 1;

            _viewId = id.ToString();
            _jobcode = JobCode; //lastFolderXElements[1];
            _path = ModelPath; //lastFolderXElements[4];
            _name = FabricatorName; //lastFolderXElements[5];

            /// -- not included
            _jobnumber = string.Empty; //lastFolderXElements[0];
            _version = string.Empty; //lastFolderXElements[3];
            /// -- 

            var newXElements = new XElement
            (
                "viewmodel",
                new XAttribute("viewid", _viewId),
                new XElement("jobnumber", _jobnumber),
                new XElement("jobcode", _jobcode),
                new XElement("name", _name),
                new XElement("version", _version),
                new XElement("path", _path),
                new XElement("servername", ""),
                new XElement("date", DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString()),
                new XElement("configuration", ""),
                new XElement("role", "")
            );
            RootElement.Add(newXElements);

            return _mainXmlDocument;
        }
}

Related Tutorials