当前位置: 首页>>代码示例>>C#>>正文


C# XDocument.Element方法代码示例

本文整理汇总了C#中System.Xml.Linq.XDocument.Element方法的典型用法代码示例。如果您正苦于以下问题:C# XDocument.Element方法的具体用法?C# XDocument.Element怎么用?C# XDocument.Element使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Linq.XDocument的用法示例。


在下文中一共展示了XDocument.Element方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: loadServerConfig

 public void loadServerConfig()
 {
     xdoc = XDocument.Load("../../../config/server_config.xml");
     BindIpInput.Text = xdoc.Element("config").Element("server_config").Element("bind_ip").Value;
     BindPortInput.Text = xdoc.Element("config").Element("server_config").Element("bind_port").Value;
     singleton.log("Server config loaded.");
 }
开发者ID:Palethorn,项目名称:Scheduler,代码行数:7,代码来源:MainWindow.cs

示例2: addTask

        public void addTask(XDocument xdoc)
        {
            XDocument message;
            XDocument header;
            Dictionary<string, string> headers = new Dictionary<string,string>();
            string title = xdoc.Element("message").Element("task").Element("title") != null ? xdoc.Element("message").Element("task").Element("title").Value : "\'\'";
            string notes = xdoc.Element("message").Element("task").Element("notes") != null ? xdoc.Element("message").Element("task").Element("notes").Value : "\'\'";
            string startdatetime = xdoc.Element("message").Element("task").Element("startdatetime") != null ? xdoc.Element("message").Element("task").Element("startdatetime").Value : "\'\'";
            string enddatetime = xdoc.Element("message").Element("task").Element("enddatetime") != null ? xdoc.Element("message").Element("task").Element("enddatetime").Value : "\'\'";
            string place = xdoc.Element("message").Element("task").Element("place") != null ? xdoc.Element("message").Element("task").Element("place").Value : "\'\'";

            OdbcDataReader r = adapter.executeQuery("insert ignore into scheduler.task(title, notes, startdatetime, enddatetime, place, fkuser) values(\'" + title + "\', \'" + notes + "\', \'" + startdatetime + "\', \'" + enddatetime + "\', \'" + place + "\', " + userId + ")", true);
            if (adapter.affectedRows() > 0)
            {
                message = formatter.createMessage("Task added.", "popup", "0");
                headers.Add("content_length", message.ToString().Length.ToString());
                headers.Add("message_type", "popup");
            }
            else
            {
                message = formatter.createMessage("Error while adding task.", "popup", "1");
                headers.Add("content_length", message.ToString().Length.ToString());
                headers.Add("message_type", "popup");
            }
            header = formatter.createHeader(headers);
            sendHeader(header);
            sendMessage(message);
            getTasks();
        }
开发者ID:Palethorn,项目名称:Scheduler,代码行数:29,代码来源:Client.cs

示例3: saveToXML

		public void saveToXML()
		{
			XDocument xdoc = new XDocument ();
			string xmlShell = @"<save><board></board><players></players><turn></turn> </save>";
			xdoc = XDocument.Parse (xmlShell);
			for (int x = 0; x < 15; x++)
			{
				XElement row = new XElement ("row");
				for (int y = 0; y < 15; y++)
				{
					row.Add(new XElement("column",board[x][y]));
				}
				xdoc.Element("save").Element ("board").Add (row);
			}
			for (int i = 0; i < players.Count; i++)
			{
				XElement player = new XElement ("player");
				player.Add (new XElement ("name", players [i].GetName ()));
				player.Add (new XElement ("bricks", players [i].GetLetters ()));
				player.Add (new XElement ("score", players [i].GetPoints()));
				xdoc.Element("save").Element("players").Add(player);
			}
			xdoc.Element("save").Element("turn").SetValue (playerturn);
			xdoc.Save ("Savestate.xml");
		}
开发者ID:HGrantt,项目名称:Monodevelop,代码行数:25,代码来源:State.cs

示例4: CanAddNode

        public void CanAddNode()
        {
            var document = new XDocument(new XElement("document", new XElement("element1"), new XElement("element2")));
            var file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            document.Save(file);
            try
            {
                var mock = new Mock<ILogger>();
                var task = new XmlAddNodeTaskExecutor
                           {
                           	File = new FileInfo(file),
                           	XPath = "/document",
                           	NodeXml = "<element3 />",
                           	Logger = mock.Object
                           };
                task.CallExecuteTask();

                document = XDocument.Load(file);
                Assert.That(document.Root, Is.Not.Null);
                // ReSharper disable PossibleNullReferenceException
                Assert.That(document.Root.Descendants().Count(), Is.EqualTo(3));
                Assert.That(document.Element("document").Element("element1"), Is.Not.Null);
                Assert.That(document.Element("document").Element("element2"), Is.Not.Null);
                Assert.That(document.Element("document").Element("element3"), Is.Not.Null);
                // ReSharper restore PossibleNullReferenceException

                var desiredLogMessage = string.Format(Resources.XmlAddNodeTaskLogMessage, task.NodeXml, task.XPath, file);
                mock.Verify(logger => logger.Log(It.Is<Level>(l => l == Level.Info), It.Is<string>(s => s.Equals(desiredLogMessage))));
            }
            finally
            {
                File.Delete(file);
            }
        }
开发者ID:aleffnull,项目名称:nant_additional,代码行数:34,代码来源:XmlAddNodeTaskFixture.cs

示例5: Entity

        public Entity(XDocument document)
        {
            id = uint.Parse(document.Element("entity").Attribute("id").Value);
            name = document.Element("entity").Attribute("name").Value;

            componentsXML = document.Element("entity").Element("components").Elements().ToList<XElement>();
        }
开发者ID:broding,项目名称:island-components-framework,代码行数:7,代码来源:Entity.cs

示例6: addConfigOption

 private static void addConfigOption(string name, bool func, XDocument doc)
 {
     if (func)
         doc.Element("Config").Add(new XElement(name, "1"));
     else
         doc.Element("Config").Add(new XElement(name, "0"));
 }
开发者ID:argoneuscze,项目名称:LoLFavorites,代码行数:7,代码来源:Config.cs

示例7: LoadXML

        public static XDocument LoadXML(string XMLfile)
        {
            XDocument LoadedXML;
            if (XMLfile == OverwatchINI)
            {
                Settings = XDocument.Load(Utilities.OverwatchINI);
                if (WinUsername != (Settings.Element("Settings").Element("UserInfo").Element("Usernames").Element("Windows").Element("WinUsername").Value))
                {
                    WinUsername = Settings.Element("Settings").Element("UserInfo").Element("Usernames").Element("Windows").Element("WinUsername").Value;
                }
                if (AvatarLocation != (Settings.Element("Settings").Element("UserInfo").Element("Usernames").Element("Windows").Element("AvatarLocation").Value))
                {
                    AvatarLocation = Settings.Element("Settings").Element("UserInfo").Element("Usernames").Element("Windows").Element("AvatarLocation").Value;
                }
                if ((Settings.Element("Settings").Element("HardwareInfo").Element("Processor").Element("Name").Value != ""))
                {
                    CPUName = Settings.Element("Settings").Element("HardwareInfo").Element("Processor").Element("Name").Value;
                }
                if (Settings.Element("Settings").Element("HardwareInfo").Element("Processor").Element("Frequency").Value != "")
                {
                    CPUFreq = Settings.Element("Settings").Element("HardwareInfo").Element("Processor").Element("Frequency").Value;
                }
                if (Settings.Element("Settings").Element("HardwareInfo").Element("MotherBoard").Value != "")
                {
                    MotherboardName = Settings.Element("Settings").Element("HardwareInfo").Element("MotherBoard").Value;
                }
                LoadedXML = Settings;
            }
            else
            {
                LoadedXML = XDocument.Load(XMLfile);

            }
            return LoadedXML;
        }
开发者ID:tjmidnight,项目名称:Overwatch,代码行数:35,代码来源:Utilities.cs

示例8: saveXml

        private void saveXml()
        {
            XDocument xmlOutput = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XComment("Jueki's Own3d.tv Stream Manager Configuration"),
                new XElement("streams")
            );

            foreach(ListViewItem lv in listView1.Items)
            {
                xmlOutput.Element("streams").Add(
                    new XElement("stream",
                        new XElement("name", lv.Text),
                        new XElement("id", lv.SubItems[2].Text)
                    )
                );
            }

            xmlOutput.Element("streams").Add(
                new XElement("config",
                    new XElement("gui",
                        new XElement("width", this.Size.Width.ToString()),
                        new XElement("height", this.Size.Height.ToString())
                    )
                )
            );

            xmlOutput.Save("streams.xml");
        }
开发者ID:ThorstenR,项目名称:Own3d.tv-Streamer,代码行数:29,代码来源:Form1.cs

示例9: Button_CreateProject_Click

        private void Button_CreateProject_Click(object sender, RoutedEventArgs e)
        {
            XDocument newProject = new XDocument(
                new XElement("Project",
                    new XElement("Name"),
                    new XElement("SDNumber"),
                    new XElement("Watchfolder"),
                    new XElement("MezzaninePassFolder"),
                    new XElement("WebPassFolder"),
                    new XElement("FailFolder"),
                    new XElement("Keyword"),
                    new XElement("ToEmailOnFail"))
                );

            foreach (var element in newProject.Element("Project").Elements())
            {
                XML_Element_Entry entry = new XML_Element_Entry();
                entry.Label_element.Content = element.Name;
                entry.ShowDialog();

                newProject.Element("Project").Element(element.Name).Value = entry.TextBox_value.Text;
            }

            newProject.Save(@"\\cob-hds-1\compression\QC\QCing\otherFiles\projects\" + newProject.Element("Project").Element("Name").Value + ".xml");
        }
开发者ID:BagpipesJohnson,项目名称:QualityControl,代码行数:25,代码来源:ProjectManagment.xaml.cs

示例10: GetMetaWebLogElement

        private static XElement GetMetaWebLogElement(XDocument document)
        {
            // ReSharper disable PossibleNullReferenceException
            try
            {
                IEnumerable<XElement> apiElements;
                if (document.Root.Attributes().Any(x => x.IsNamespaceDeclaration && x.Value == RsdNamespace))
                {
                    apiElements = document
                        .Element(XName.Get("rsd", RsdNamespace))
                        .Element(XName.Get("service", RsdNamespace))
                        .Element(XName.Get("apis", RsdNamespace))
                        .Elements(XName.Get("api", RsdNamespace));
                }
                else
                {
                    apiElements = document
                        .Element(XName.Get("rsd"))
                        .Element(XName.Get("service"))
                        .Element(XName.Get("apis"))
                        .Elements(XName.Get("api"));
                }

                return apiElements.SingleOrDefault(e => e.Attribute("name").Value.ToLower() == "metaweblog");
            }
            catch (NullReferenceException)
            {
                return null;
            }
            // ReSharper restore PossibleNullReferenceException
        }
开发者ID:rereadyou,项目名称:DownmarkerWPF,代码行数:31,代码来源:RsdService.cs

示例11: Export

        public ActionResult Export() {
            var content = _contentManager
                .Query(VersionOptions.Published)
                .List();

            XDocument export = new XDocument();
            export.Add(new XElement("Orchard"));
            export.Element("Orchard").Add(new XElement("Data"));
            foreach(var contentItem in content) {
                export.Element("Orchard").Element("Data").Add(_contentManager.Export(contentItem));
            }

            StringBuilder xml = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings()
                {Encoding = Encoding.UTF8, Indent = true, NewLineHandling = NewLineHandling.Entitize, NewLineOnAttributes = true};
            using (XmlWriter w = XmlWriter.Create(xml, settings)) {
                export.WriteTo(w);
                w.Flush();
            }

            return new ContentResult() {
                Content = xml.ToString(),
                ContentType = "text/xml",
                ContentEncoding = Encoding.UTF8
            };
        }
开发者ID:JustGiving,项目名称:Tad.ContentSync,代码行数:26,代码来源:ContentImportExportController.cs

示例12: addMyItem

        ////This is a basic function that adds an item to an xdocument.  It is called by various other functions.
        ////It receives the name of the XDocument, the filename that identifies where it is stored, the name of the item,
        ////whether it is enabled, and the string for the combination such as in salvage or empty for mobs and trophies,
        ////the GUID as a string -- which may or may not be kept, and a bool for if it is a partial name, and the number of subitems in the xml file
        ////the function simply adds the item to the file and then saves the file.
        private void addMyItem(XDocument xdoc, string filename, string mid, bool mexact, int mitem)
        {
            try
            {
                switch (mitem)
                {
                    case 1:
                        xdoc.Element("GameItems").Add(new XElement("item",
                           new XElement("key", sname),
                           new XElement("checked", mchecked),
                           new XElement("isexact", mexact),
                           new XElement("Guid", mid)));
                        break;
                    case 2:
                        xdoc.Element("GameItems").Add(new XElement("item",
                            new XElement("key", sname),
                            new XElement("checked", mchecked),
                            new XElement("isexact", mexact),
                            new XElement("Guid", mMaxLoot)));
                        break;
                }

                xdoc.Save(filename);

                if (xdoc == xdocTrophies)
                { populateTrophysListBox(); }
                else if (xdoc == xdocMobs)
                { populateMobsListBox(); }
            }
            catch (Exception ex) { LogError(ex); }
        }
开发者ID:Kkarinisme,项目名称:GearTemp,代码行数:36,代码来源:SetupUserInterface.cs

示例13: OpfFile

        internal OpfFile(string fileName)
        {
            Document = XDocument.Load(fileName);

            _metadata = Document.Element("metadata");
            _manifest = Document.Element("manifest");
            _spine = Document.Element("spine");
        }
开发者ID:Mitch528,项目名称:Epub.Net,代码行数:8,代码来源:OpfFile.cs

示例14: btnSave_Click

    protected void btnSave_Click(object sender, EventArgs e)
    {
        doc = XDocument.Load(Server.MapPath("~/App_Data/Images.xml"));
        if (this.drpLetters.SelectedIndex > 0) // Edit mode
        {
            IEnumerable<XElement> elements = doc.Element("Images").Elements("Image").Where(an => an.Attribute("id").Value == this.drpLetters.SelectedValue);
            foreach (XElement item in elements)
            {
                item.Attribute("isActive").Value = this.chkIsActive.Checked.ToString();
                item.Element("Title").Value = this.txtTitle.Text;
            }
            doc.Save(Server.MapPath("~/App_Data/Images.xml"));
            if (this.fluLetter.HasFile)
            {
                if (this.fluLetter.PostedFile.ContentType.Equals("image/pjpeg") || this.fluLetter.PostedFile.ContentType.Equals("image/x-png"))
                {
                    string file = string.Format("{0}/{1}.jpg", Server.MapPath("~/LettImg"), this.drpLetters.SelectedValue);
                    System.IO.File.Delete(file);
                    this.fluLetter.PostedFile.SaveAs(file);
                }
                else
                {
                    this.lblMessage.Text = "فرمت عکس jpg نمیباشد";
                }
            }
            this.lblMessage.Text = Public.EDITMESSAGE;
        }
        else // Add mode
        {
            if (this.fluLetter.HasFile)
            {
                if (this.fluLetter.PostedFile.ContentType.Equals("image/pjpeg") || this.fluLetter.PostedFile.ContentType.Equals("image/x-png"))
                {
                    string maxId = doc.Element("Images").Elements("Image").Max(tst => tst.Attribute("id").Value);
                    string nextId = maxId == null ? "1" : (byte.Parse(maxId) + 1).ToString();
                    doc.Element("Images").Add(new XElement("Image", new XAttribute("id", nextId),
                                                                                         new XAttribute("isActive", this.chkIsActive.Checked.ToString()),
                                                                                         new XElement("Title", this.txtTitle.Text.Trim())));

                    doc.Save(Server.MapPath("~/App_Data/Images.xml"));
                    this.fluLetter.PostedFile.SaveAs(string.Format("{0}/{1}.jpg", Server.MapPath("~/LettImg"), nextId));
                    this.lblMessage.Text = Public.SAVEMESSAGE;
                }
                else
                {
                    this.lblMessage.Text = "فرمت عکس jpg نمیباشد";
                }
            }
        }

        this.drpLetters.DataSource = doc.Element("Images").Elements("Image").Select(an => new { Id = an.Attribute("id").Value, Title = an.Element("Title").Value });
        this.drpLetters.DataBind();
        this.drpLetters.Items.Insert(0, "- جدید -");
        this.drpLetters.SelectedIndex = 0;
        this.chkIsActive.Checked = false;
        this.txtTitle.Text = null;
        this.imgLetter.ImageUrl = null;
    }
开发者ID:BehnamAbdy,项目名称:Ajancy,代码行数:58,代码来源:Images.aspx.cs

示例15: ThemeSettings

 public ThemeSettings(XDocument settingDoc)
 {
     XElement firing = settingDoc.Element("themeSettings").Element("firingTypes");
     foreach (XElement ft in firing.Elements())
         this._firingTypes.Add(ft.Value);
     XElement damage = settingDoc.Element("themeSettings").Element("damageTypes");
     foreach (XElement dt in damage.Elements())
         this._damageTypes.Add(dt.Value);
 }
开发者ID:NevermoreDCE,项目名称:Dalek,代码行数:9,代码来源:ThemeSettings.cs


注:本文中的System.Xml.Linq.XDocument.Element方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。