本文整理匯總了C#中System.Xml.Linq.XContainer.Element方法的典型用法代碼示例。如果您正苦於以下問題:C# XContainer.Element方法的具體用法?C# XContainer.Element怎麽用?C# XContainer.Element使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.Linq.XContainer
的用法示例。
在下文中一共展示了XContainer.Element方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Populate
public override void Populate(XContainer root)
{
root = root.Element("result");
base.Populate(root);
Url = root.Element("url").Value;
}
示例2: GetAccount
private static IAccount GetAccount(XContainer accountContainer)
{
if (accountContainer == null) return null;
return new Account
{
Number = accountContainer.Element("Number").GetTextValue(),
CountryCode = accountContainer.Element("CountryCode").GetTextValue()
};
}
示例3: UpdatePropertyElement
/// <summary>
/// Updates the property element.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="elementPosition">The element position.</param>
/// <param name="fileId">The file id.</param>
private static void UpdatePropertyElement(XContainer property, SourceElementPosition elementPosition, string fileId)
{
property.Add(new XElement("FileRef", new XAttribute("uid", fileId)));
var seqpnt = new XElement(
"SequencePoint",
new XAttribute("vc", property.Element("MethodPoint").Attribute("vc").Value),
new XAttribute("sl", elementPosition.Start));
property.Element("SequencePoints").Add(seqpnt);
}
示例4: BuildUserInfo
private static UserInfo BuildUserInfo(XContainer user)
{
// ReSharper disable PossibleNullReferenceException
return new UserInfo
{
Name = user.Element("screen_name").Value,
Location = user.Element("location").Value,
FriendCount = int.Parse(user.Element("friends_count").Value),
FollowerCount = int.Parse(user.Element("followers_count").Value)
};
// ReSharper restore PossibleNullReferenceException
}
示例5: WufooData
/// <summary>
/// Constructor for user data
/// </summary>
/// <param name="xml">XContainer containing user data</param>
/// <param name="adminUser">Admin username</param>
public WufooData(XContainer xml, string adminUser)
{
// set user properties
AdminUserName = adminUser;
Hash = xml.Element("Hash").ElementValueNull();
Title = xml.Element("User").ElementValueNull();
ApiKey = xml.Element("ApiKey").ElementValueNull();
FormsUrl = xml.Element("LinkForms").ElementValueNull();
CreateForms = xml.Element("CreateForms").ElementValueNull().Equals("1");
Created = DateTime.MinValue;
Modified = DateTime.MinValue;
IsForm = false;
}
示例6: Station
public Station(XContainer xc)
{
name = xc.Element("name").Value;
id = Convert.ToInt32(xc.Element("id").Value);
lat = Convert.ToDouble(xc.Element("lat").Value);
lng = Convert.ToDouble(xc.Element("long").Value);
installed = Convert.ToBoolean(xc.Element("installed").Value);
locked = Convert.ToBoolean(xc.Element("locked").Value);
locked = Convert.ToBoolean(xc.Element("temporary").Value);
bikeCount = Convert.ToInt32(xc.Element("nbBikes").Value);
dockCount = Convert.ToInt32(xc.Element("nbEmptyDocks").Value);
}
示例7: GetGuids
internal static List<string> GetGuids(XContainer owningElement, string propertyName)
{
var propElement = owningElement.Element(propertyName);
return (propElement == null) ? new List<string>() : (from osEl in propElement.Elements(SharedConstants.Objsur)
select osEl.Attribute(SharedConstants.GuidStr).Value.ToLowerInvariant()).ToList();
}
示例8: GetField
private static string GetField(XContainer el, string fieldName)
{
var fld = el.Element(fieldName);
return fld != null
? fld.Value
: "<Missing>";
}
示例9: UpdateGeocodes
public void UpdateGeocodes(XContainer result, Org org)
{
if (result == null) throw new ArgumentNullException("result");
var element = result.Element("geometry");
if (element == null) return;
var locationElement = element.Element("location");
if (locationElement == null) return;
var lat = locationElement.Element("lat");
if (lat != null)
{
org.Lat = lat.Value.ToNullableDouble();
org.Modified = DateTime.Now;
}
var lng = locationElement.Element("lng");
if (lng != null)
{
org.Lon = lng.Value.ToNullableDouble();
org.Modified = DateTime.Now;
}
}
示例10: GetValue
private static string GetValue(XContainer container, string elementName)
{
var typeElemment = container.Element(elementName);
if (typeElemment == null)
throw new ArgumentException("找不到元素 MsgType。");
return typeElemment.Value;
}
示例11: UpdatePropertyElement
/// <summary>
/// Updates the property element.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="elementPosition">The element position.</param>
/// <param name="fileId">The file id.</param>
private static void UpdatePropertyElement(XContainer property, SourceElementPosition elementPosition, string fileId)
{
foreach (var pt in property.Element("code").Elements().Take(1))
{
pt.Add(new XAttribute("sl", elementPosition.Start));
pt.Add(new XAttribute("fid", fileId));
}
}
示例12: FillProperties
private void FillProperties(XContainer xml)
{
if (xml == null) return;
var title = xml.Element("title");
var subTitle = xml.Element("subtitle");
var location = xml.Element("location");
var phone = xml.Element("phone");
var url = xml.Element("url");
var urlText = xml.Element("urlText");
if (title != null) Title = string.IsNullOrEmpty(title.Value) ? null : title.Value;
if (subTitle != null) SubTitle = string.IsNullOrEmpty(subTitle.Value) ? null : subTitle.Value;
if (location != null) Location = string.IsNullOrEmpty(location.Value) ? null : location.Value;
if (phone != null) Phone = string.IsNullOrEmpty(phone.Value) ? null : phone.Value;
if (url != null) Url = string.IsNullOrEmpty(url.Value) ? null : url.Value;
if (urlText != null) UrlText = string.IsNullOrEmpty(urlText.Value) ? null : urlText.Value;
var keyValueList = xml.Element("departmentOrDayOfWeekToTimeList");
if (keyValueList == null) return;
var items = keyValueList.Descendants("item");
foreach (var item in items)
{
var key = item.Attribute("key");
if (key == null) continue;
var value = item.Element("value");
if (value != null) LocationOrDayOfWeekToTime.Add(key.Value, value.Value ?? string.Empty);
}
}
示例13: RegisterExecutionTypes
private void RegisterExecutionTypes(XContainer root, OpcodeLookup lookup)
{
foreach (XElement element in root.Element("scriptTypes").Descendants("type"))
{
var opcode = (ushort) XMLUtil.GetNumericAttribute(element, "opcode");
string name = XMLUtil.GetStringAttribute(element, "name");
lookup.RegisterScriptType(name, opcode);
}
}
示例14: FillProperties
public void FillProperties(XContainer xml)
{
if (xml == null) return;
var title = xml.Element("title");
var phone = xml.Element("phone");
var fax = xml.Element("fax");
var email = xml.Element("email");
var visitingAddress = xml.Element("visitingaddress");
var address = xml.Element("address");
if (title != null) Title = string.IsNullOrEmpty(title.Value) ? null : title.Value;
if (phone != null) Phone = string.IsNullOrEmpty(phone.Value) ? null : phone.Value;
if (fax != null) Fax = string.IsNullOrEmpty(fax.Value) ? null : fax.Value;
if (email != null) Email = string.IsNullOrEmpty(email.Value) ? null : email.Value;
if (visitingAddress != null) VisitingAddress = string.IsNullOrEmpty(visitingAddress.Value) ? null : visitingAddress.Value;
if (address != null) Address = string.IsNullOrEmpty(address.Value) ? null : address.Value;
var contactPersons = xml.Element("contact-persons");
if (contactPersons != null)
{
ContactPersons = new List<ContactPerson>();
foreach (var person in contactPersons.Descendants("person"))
{
var name = person.Element("name");
if (name == null) continue;
if (string.IsNullOrEmpty(name.Value)) continue;
var cp = new ContactPerson {Name = name.Value};
var positionAsElement = person.Element("position");
var emailAsElement = person.Element("email");
var phoneAsElement = person.Element("phone");
if (positionAsElement != null && !string.IsNullOrEmpty(positionAsElement.Value))
cp.Position = positionAsElement.Value;
if (emailAsElement != null && !string.IsNullOrEmpty(emailAsElement.Value))
cp.Email = emailAsElement.Value;
if (phoneAsElement != null && !string.IsNullOrEmpty(phoneAsElement.Value))
cp.Phone = phoneAsElement.Value;
ContactPersons.Add(cp);
}
}
var genericFields = xml.Element("generic-fields");
if (genericFields == null) return;
GenericFields = new List<string>();
var fields = genericFields.Descendants("field");
foreach (var field in fields.Where(field => field != null && !string.IsNullOrEmpty(field.Value))){
GenericFields.Add(field.Value);
}
}
示例15: GetCountry
private static ICountry GetCountry(XContainer countryContainer)
{
if (countryContainer == null) return null;
return new Country
{
Code = countryContainer.Element("CountryCode").GetTextValue(),
Name = countryContainer.Element("CountryName").GetTextValue()
};
}