本文整理汇总了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.");
}
示例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();
}
示例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");
}
示例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);
}
}
示例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>();
}
示例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"));
}
示例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;
}
示例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");
}
示例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");
}
示例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
}
示例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
};
}
示例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); }
}
示例13: OpfFile
internal OpfFile(string fileName)
{
Document = XDocument.Load(fileName);
_metadata = Document.Element("metadata");
_manifest = Document.Element("manifest");
_spine = Document.Element("spine");
}
示例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;
}
示例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);
}