本文整理汇总了C#中XElement.Nodes方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.Nodes方法的具体用法?C# XElement.Nodes怎么用?C# XElement.Nodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XElement
的用法示例。
在下文中一共展示了XElement.Nodes方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromXElement
/// <summary>
/// Converts a given <see cref="T:XElement"/> into an <see cref="T:Account"/>.
/// </summary>
/// <param name="element">The <see cref="T:XElement"/> to convert.</param>
/// <returns>The newly created <see cref="T:Account"/>.</returns>
public Account FromXElement(XElement element)
{
Account account = AccountFactory.Create(element.Name.LocalName);
foreach (XElement childNode in element.Nodes()) {
switch (childNode.Name.LocalName) {
case "AccountID":
account.AccountID = new Guid(childNode.Value);
break;
case "CreatedByUsername":
account.CreatedByUsername = childNode.Value;
break;
case "CreatedDate":
account.CreatedDate = DateTime.Parse(childNode.Value);
break;
case "Description":
account.Description = childNode.Value;
break;
case "Name":
account.Name = childNode.Value;
break;
case "UpdatedByUsername":
account.UpdatedByUsername = childNode.Value;
break;
case "UpdatedDate":
account.UpdatedDate = DateTime.Parse(childNode.Value);
break;
case "ChangeSetHistory":
ChangeSetHistoryXElementAdapter adapter = new ChangeSetHistoryXElementAdapter();
account.ChangeSetHistory = adapter.FromXElement(childNode);
break;
}
}
return account;
}
示例2: FromXElement
/// <summary>
/// Converts a given <see cref="T:XElement"/> into a <see cref="T:ChangeSetHistory"/>.
/// </summary>
/// <param name="element">The <see cref="T:XElement"/> to convert.</param>
/// <returns>The newly created <see cref="T:ChangeSetHistory"/>.</returns>
public ChangeSetHistory FromXElement(XElement element)
{
ChangeSetHistory history = new ChangeSetHistory();
foreach (XElement changeSetElement in element.Nodes()) {
ChangeSet changeSet = new ChangeSet();
// Get the change set details
foreach (XElement changeSetElementChild in changeSetElement.Nodes()) {
if (changeSetElementChild.Name.LocalName == "Applied") {
changeSet.Applied = DateTime.Parse(changeSetElementChild.Value);
} else if (changeSetElementChild.Name.LocalName == "Username") {
changeSet.Username = changeSetElementChild.Value;
} else if (changeSetElementChild.Name.LocalName == "Change") {
Change change = new Change();
foreach (XElement changeElement in changeSetElementChild.Nodes()) {
if (changeElement.Name.LocalName == "PropertyName") {
change.PropertyName = changeElement.Value;
} else if (changeElement.Name.LocalName == "OldValue") {
change.OldValue = changeElement.Value;
} else if (changeElement.Name.LocalName == "NewValue") {
change.NewValue = changeElement.Value;
}
}
changeSet.Changes.Add(change);
}
}
history.Append(changeSet);
}
return history;
}
示例3: FromXElement
/// <summary>
/// Converts a given <see cref="T:XElement"/> into a <see cref="T:Transaction"/>.
/// </summary>
/// <param name="element">The <see cref="T:XElement"/> to convert.</param>
/// <param name="workbook">The <see cref="T:Workbook"/> to use to fetch additional information for the <see cref="Transaction"/>.</param>
/// <returns>The newly created <see cref="T:Transaction"/>.</returns>
public Transaction FromXElement(XElement element, Workbook workbook)
{
Transaction transaction = new Transaction();
foreach (XElement childNode in element.Nodes()) {
switch (childNode.Name.LocalName) {
case "DebitAccountID":
transaction.DebitAccount = workbook.FetchAccount(new Guid(childNode.Value));
break;
case "CreditAccountID":
transaction.CreditAccount = workbook.FetchAccount(new Guid(childNode.Value));
break;
case "CreatedByUsername":
transaction.CreatedByUsername = childNode.Value;
break;
case "CreatedDate":
transaction.CreatedDate = DateTime.Parse(childNode.Value);
break;
case "Date":
transaction.Date = DateTime.Parse(childNode.Value);
break;
case "Particulars":
transaction.Particulars = childNode.Value;
break;
case "TransactionID":
transaction.TransactionID = new Guid(childNode.Value);
break;
case "Value":
transaction.Value = decimal.Parse(childNode.Value);
break;
case "UpdatedByUsername":
transaction.UpdatedByUsername = childNode.Value;
break;
case "UpdatedDate":
transaction.UpdatedDate = DateTime.Parse(childNode.Value);
break;
case "ChangeSetHistory":
ChangeSetHistoryXElementAdapter adapter = new ChangeSetHistoryXElementAdapter();
transaction.ChangeSetHistory = adapter.FromXElement(childNode);
break;
}
}
return transaction;
}
示例4: NodesOnXElementBeforeAndAfter
public static void NodesOnXElementBeforeAndAfter()
{
XElement a = new XElement("A", "a"), b = new XElement("B", "b");
a.Add(b);
IEnumerable<XNode> nodes = a.Nodes();
Assert.Equal(2, nodes.Count());
b.Remove();
Assert.Equal(1, nodes.Count());
}
示例5: SetWeatherNextForecast
/// <summary>
/// Sets the weather next days forecast.
/// </summary>
/// <returns>
/// <c>true</c>, if weather next forecast was set, <c>false</c> otherwise.
/// </returns>
/// <param name='actualValuesAndForecast'>
/// Actual values and forecast.
/// </param>
public bool SetWeatherNextForecast(XElement actualValuesAndForecast)
{
DateTime today = DateTime.Now;
DayOfWeek dayName = today.DayOfWeek;
bool isFirstCorrected = false;
bool result = true;
try {
//now next days forecast
List<XNode> nodeForecastAux = actualValuesAndForecast.Nodes ().Where (desc => desc.ToString ().Contains ("forecast") && desc.ToString ().Contains ("day")).ToList ();
List<XNode> nodeForecast = new List<XNode> ();
XNode actualDayForecastInfo = null;
for (int i = 0; i < nodeForecastAux.Count; i++) {
if (isFirstCorrected) {
nodeForecast.Add (nodeForecastAux [i]);
} else {
string codeDay = ((XElement)nodeForecastAux [i]).Attribute ("day").Value.ToString ().ToUpper ();
DayOfWeek nodeDayName = WeatherControl.GetDayOfWeek (codeDay.ToUpper ());
//check if the first day is today (it should be)
if (nodeDayName == dayName) {
isFirstCorrected = true;
actualDayForecastInfo = nodeForecastAux[i];
}
}
}
if(actualDayForecastInfo != null)
{
this.ActualForecast = new WeatherForecast (actualDayForecastInfo);
}
else
{
this.ActualForecast = new WeatherForecast ();
}
//we made the next days predictions
if (nodeForecast.Count > 0) {
this.NextForecasts.Clear ();
foreach(XNode prediction in nodeForecast)
{
this.NextForecasts.Add (new WeatherForecast (prediction));
}
} else { //error, clear result
this.NextForecasts.Clear ();
result = false;
}
} catch (Exception ex) {
//log.Error("Error in SetWeatherNextForecast. Reason: " +ex.Message);
result = false;
}
return result;
}
示例6: SetWeatherActualForecast
/// <summary>
/// Sets the weather actual forecast.
/// </summary>
/// <returns>
/// <c>true</c>, if weather actual forecast was set, <c>false</c> otherwise.
/// </returns>
/// <param name='obCurrentConditions'>
/// Ob current conditions.
/// </param>
public bool SetWeatherActualForecast(XElement obCurrentConditions, XNode actualValue)
{
DateTime today = DateTime.Now;
bool result = true;
try {
//get sunset and sunrise
XNode timeInfoNode = obCurrentConditions.Nodes ().Where (desc => desc.ToString ().Contains ("sunrise") && desc.ToString ().Contains ("sunset")).FirstOrDefault ();
this.Day = new DateTime (today.Year, today.Month, today.Day);
this.DayOfWeekDescription = this.Day.DayOfWeek.ToString () + ",";
this.DayDescription = this.Day.ToString ("MMMM", System.Globalization.CultureInfo.InvariantCulture) + " " + this.Day.Day;
this.SunriseDescription = ((XElement)timeInfoNode).Attribute ("sunrise").Value.ToString ();
this.SunsetDescription = ((XElement)timeInfoNode).Attribute ("sunset").Value.ToString ();
//decode sunrise and sunset
this.Sunrise = WeatherControl.GetDay (today, this.SunriseDescription);
this.Sunset = WeatherControl.GetDay (today, this.SunsetDescription);
//get the rest of the data from the next node
this.CurrentTemperature = Convert.ToInt32 (((XElement)actualValue).Attribute ("temp").Value.ToString ());
this.WeatherDescription = ((XElement)actualValue).Attribute ("text").Value.ToString ();
this.WeatherDescriptionCode = ((XElement)actualValue).Attribute ("code").Value.ToString ();
this.WeatherCode = (WeatherCode)Enum.Parse (typeof(WeatherCode), this.WeatherDescriptionCode);
} catch (Exception ex) {
//log.Error("Error in SetWeatherActualForecast. Reason: " +ex.Message);
result = false;
}
return result;
}
示例7: ElementDynamic
public void ElementDynamic()
{
XElement helper = new XElement("helper", new XText("ko"), new XText("ho"));
object[] content = new object[]
{
"text1", new object[] { new string[] { "t1", null, "t2" }, "t1t2" }, new XProcessingInstruction("PI1", ""),
new XProcessingInstruction("PI1", ""), new XProcessingInstruction("PI2", "click"),
new object[] { new XElement("X", new XAttribute("id", "a1"), new XText("hula")), new XElement("X", new XText("hula"), new XAttribute("id", "a1")) },
new XElement("{nsp}X", new XAttribute("id", "a1"), "hula"),
new object[] { new XText("koho"), helper.Nodes() },
new object[] { new XText[] { new XText("hele"), new XText(""), new XCData("youuu") }, new XText[] { new XText("hele"), new XCData("youuu") } },
new XComment(""), new XComment("comment"),
new XAttribute("id1", "nono"), new XAttribute("id3", "nono2"), new XAttribute("{nsa}id3", "nono2"),
new XAttribute("{nsb}id3", "nono2"), new XAttribute("xmlns", "default"),
new XAttribute(XNamespace.Xmlns + "a", "nsa"), new XAttribute(XNamespace.Xmlns + "p", "nsp"),
new XElement("{nsa}X", new XAttribute("id", "a1"), "hula", new XAttribute("{nsb}aB", "hele"), new XElement("{nsc}C"))
};
foreach (object[] objs in content.NonRecursiveVariations(4))
{
XElement e1 = new XElement("E", ExpandAndProtectTextNodes(objs, 0));
XElement e2 = new XElement("E", ExpandAndProtectTextNodes(objs, 1));
VerifyComparison(true, e1, e2);
e1.RemoveAll();
e2.RemoveAll();
}
}
示例8: Element3
public void Element3()
{
XElement e1 = new XElement("A", "string_content");
XElement e2 = new XElement("A", new XText("string"), new XText("_content"));
XElement e3 = new XElement("A", new XText("string"), new XComment("comm"), new XText("_content"));
XElement e4 = new XElement("A", new XText("string"), new XCData("_content"));
VerifyComparison(true, e1, e2);
VerifyComparison(false, e1, e3);
VerifyComparison(false, e2, e3);
VerifyComparison(false, e1, e4);
VerifyComparison(false, e2, e4);
VerifyComparison(false, e3, e4);
e3.Nodes().First(n => n is XComment).Remove();
VerifyComparison(true, e1, e3);
VerifyComparison(true, e2, e3);
}