本文整理匯總了C#中System.Xml.Linq.XElement.Attribute方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.Attribute方法的具體用法?C# XElement.Attribute怎麽用?C# XElement.Attribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.Attribute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: LoadSound
private SoundInfo LoadSound(XElement soundNode, string basePath)
{
SoundInfo sound = new SoundInfo { Name = soundNode.RequireAttribute("name").Value };
sound.Loop = soundNode.TryAttribute<bool>("loop");
sound.Volume = soundNode.TryAttribute<float>("volume", 1);
XAttribute pathattr = soundNode.Attribute("path");
XAttribute trackAttr = soundNode.Attribute("track");
if (pathattr != null)
{
sound.Type = AudioType.Wav;
sound.Path = FilePath.FromRelative(pathattr.Value, basePath);
}
else if (trackAttr != null)
{
sound.Type = AudioType.NSF;
int track;
if (!trackAttr.Value.TryParse(out track) || track <= 0) throw new GameXmlException(trackAttr, "Sound track attribute must be an integer greater than zero.");
sound.NsfTrack = track;
sound.Priority = soundNode.TryAttribute<byte>("priority", 100);
}
else
{
sound.Type = AudioType.Unknown;
}
return sound;
}
示例2: buildObjectFromXML
public static GameObject buildObjectFromXML(XElement xmlObject)
{
string objectName = (xmlObject.Attribute("name") != null) ? ((string)xmlObject.Attribute("name")) : ("Unit Map Object");
string sprite = "testTile_White_Black";
return generateObject(objectName, sprite);
}
示例3: CharacterAttachmentBrand
internal CharacterAttachmentBrand(CharacterAttachmentSlot slot, XElement element)
{
Slot = slot;
// Set up strings
var brandNameAttribute = element.Attribute("Name");
if (brandNameAttribute != null)
Name = brandNameAttribute.Value;
var brandThumbnailAttribute = element.Attribute("Thumbnail");
if (brandThumbnailAttribute != null)
ThumbnailPath = brandThumbnailAttribute.Value;
// Get attachments
var slotAttachmentElements = element.Elements("Attachment");
int count = slotAttachmentElements.Count();
if (Slot.CanBeEmpty)
count++;
var slotAttachments = new CharacterAttachment[count];
for (int i = 0; i < slotAttachmentElements.Count(); i++)
{
var slotAttachmentElement = slotAttachmentElements.ElementAt(i);
slotAttachments[i] = new CharacterAttachment(Slot, slotAttachmentElement);
}
if (Slot.CanBeEmpty)
slotAttachments[slotAttachmentElements.Count()] = new CharacterAttachment(Slot, null);
Attachments = slotAttachments;
}
示例4: AccessRequest
public AccessRequest(string cls, XElement xElement) {
var nameAttr = xElement.Attribute("name");
string name = nameAttr == null ? "" : nameAttr.Value;
Identifier = new IdentifierImpl(cls, name);
checkType = xElement.Attribute("type").Value;
requiredClaims = xElement.Descendants("claim").Select(c => new Claim(c.Attribute("type").Value, c.Attribute("value").Value)).ToList();
}
示例5: MissionFitting
public MissionFitting(XElement missionfitting)
{
Mission = (string)missionfitting.Attribute("mission") ?? "";
Faction = (string)missionfitting.Attribute("faction") ?? "Default";
Fitting = (string)missionfitting.Attribute("fitting") ?? "";
Ship = (string)missionfitting.Attribute("ship") ?? "";
}
示例6: FixElement
internal override bool FixElement(XElement rt, FwDataFixer.ErrorLogger errorLogger)
{
var xaClass = rt.Attribute("class").Value;
switch (xaClass)
{
case "StStyle":
var guid = rt.Attribute("guid").Value;
if (!m_deletedGuids.Contains(guid))
return true; // keep it as far as we're concerned.
var name = rt.Element("Name").Element("Uni").Value; // none can be null or we wouldn't have listed it for deletion
errorLogger(String.Format(Strings.ksRemovingDuplicateStyle, name), true);
return false; // This element must go away!
case "LangProject":
case "Scripture":
var styles = rt.Element("Styles");
if (styles == null)
return true;
// Removing these here prevents additional error messages about missing objects, since the
// targets of these objsurs are no longer present.
foreach (var objsur in styles.Elements().ToArray()) // ToArray so as not to modify collection we're iterating over
{
var surGuid = objsur.Attribute("guid").Value;
if (m_deletedGuids.Contains(surGuid))
objsur.Remove();
}
break;
}
return true; // we're not deleting it.
}
示例7: Effect
public Effect(XElement element)
{
if (element.Attribute("id") != null)
Id = element.Attribute("id").Value;
if (element.Attribute("name") != null)
Name = element.Attribute("name").Value;
var commonElement = element.Element(XName.Get("profile_COMMON", COLLADAConverter.Namespace));
if (commonElement != null)
{
var techniqueElement = commonElement.Element(XName.Get("technique", COLLADAConverter.Namespace));
if (techniqueElement != null)
{
var phongElement = techniqueElement.Element(XName.Get("phong", COLLADAConverter.Namespace));
if (phongElement != null)
{
Emission = XmlReaderHelper.ReadColor(phongElement.Element(XName.Get("emission", COLLADAConverter.Namespace)).Element(XName.Get("color", COLLADAConverter.Namespace)));
Ambient = XmlReaderHelper.ReadColor(phongElement.Element(XName.Get("ambient", COLLADAConverter.Namespace)).Element(XName.Get("color", COLLADAConverter.Namespace)));
Specular = XmlReaderHelper.ReadColor(phongElement.Element(XName.Get("specular", COLLADAConverter.Namespace)).Element(XName.Get("color", COLLADAConverter.Namespace)));
Shininess = XmlReaderHelper.ReadFloat(phongElement.Element(XName.Get("shininess", COLLADAConverter.Namespace)).Element(XName.Get("float", COLLADAConverter.Namespace)));
Reflectivity = XmlReaderHelper.ReadFloat(phongElement.Element(XName.Get("reflectivity", COLLADAConverter.Namespace)).Element(XName.Get("float", COLLADAConverter.Namespace)));
Transparent = XmlReaderHelper.ReadColor(phongElement.Element(XName.Get("transparent", COLLADAConverter.Namespace)).Element(XName.Get("color", COLLADAConverter.Namespace)));
Transparency = XmlReaderHelper.ReadFloat(phongElement.Element(XName.Get("transparency", COLLADAConverter.Namespace)).Element(XName.Get("float", COLLADAConverter.Namespace)));
var diffuseElement = phongElement.Element(XName.Get("diffuse", COLLADAConverter.Namespace));
var diffuseColorElement = diffuseElement.Element(XName.Get("color", COLLADAConverter.Namespace));
if (diffuseColorElement != null)
Diffuse = XmlReaderHelper.ReadColor(diffuseColorElement);
}
}
}
}
示例8: SvgPatternElement
//==========================================================================
public SvgPatternElement(SvgDocument document, SvgBaseElement parent, XElement patternElement)
: base(document, parent, patternElement)
{
XAttribute pattern_transform_attribute = patternElement.Attribute("patternTransform");
if(pattern_transform_attribute != null)
PatternTransform = SvgTransform.Parse(pattern_transform_attribute.Value);
XAttribute pattern_units_attribute = patternElement.Attribute("patternUnits");
if(pattern_units_attribute != null)
switch(pattern_units_attribute.Value)
{
case "objectBoundingBox":
PatternUnits = SvgPatternUnits.ObjectBoundingBox;
break;
case "userSpaceOnUse":
PatternUnits = SvgPatternUnits.UserSpaceOnUse;
break;
default:
throw new NotImplementedException(String.Format("patternUnits value '{0}' is no supported", pattern_units_attribute.Value));
}
XAttribute width_attribute = patternElement.Attribute("width");
if(width_attribute != null)
Width = SvgLength.Parse(width_attribute.Value);
XAttribute height_attribute = patternElement.Attribute("height");
if(height_attribute != null)
Height = SvgLength.Parse(height_attribute.Value);
}
示例9: ParseCruiseControlExportToCruiseControlProject
/// <summary>
/// Parses a Cruise Control export 'Project' node into a CruiseControlProject object
/// </summary>
/// <param name="element">XElement object</param>
/// <returns>Cruise Control Project</returns>
public static CruiseControlProject ParseCruiseControlExportToCruiseControlProject(XElement element)
{
if (element == null)
return null;
var project = new CruiseControlProject();
var name = element.Attribute("name");
if (name != null)
project.Name = name.Value;
var lastBuildStatus = element.Attribute("lastBuildStatus");
if (lastBuildStatus != null)
project.LastBuildStatus = lastBuildStatus.Value;
var lastBuildTime = element.Attribute("lastBuildTime");
DateTime date;
if (lastBuildTime != null && DateTime.TryParse(lastBuildTime.Value, out date))
project.LastBuildTime = date;
var url = element.Attribute("webUrl");
if (url != null)
project.WebUrl = url.Value;
return project;
}
示例10: MiningCrystals
public MiningCrystals(XElement MiningCrystals)
{
TypeId = (int)MiningCrystals.Attribute("typeId");
OreType = (OreType)Enum.Parse(typeof(OreType), (string)MiningCrystals.Attribute("oreType"));
Quantity = (int)MiningCrystals.Attribute("quantity");
Description = (string)MiningCrystals.Attribute("description") ?? (string)MiningCrystals.Attribute("typeId");
}
示例11: Font
public Font(string name, XElement fontXmlNode, GraphicsDevice device)
{
XAttribute xwidth = fontXmlNode.Attribute("width");
XAttribute xheight = fontXmlNode.Attribute("height");
string filename = fontXmlNode.Value;
if (xwidth == null || xheight == null)
throw new Exception("Width or Height attribute for font is missing");
int width;
int height;
if (!int.TryParse(xwidth.Value, out width))
throw new Exception("Width value is invalid: " + xwidth.Value);
if (!int.TryParse(xheight.Value, out height))
throw new Exception("Height value is invalid: " + xheight.Value);
System.IO.Stream fontStream = System.IO.File.OpenRead(filename);
this.Image = Texture2D.FromStream(device, fontStream);
fontStream.Dispose();
FilePath = filename;
Name = name;
CellWidth = width;
CellHeight = height;
Generate();
}
示例12: Deserialize
/// <summary>
/// Initializes the <see cref="ValueAction"/>.
/// </summary>
/// <param name="xml">
/// The XML the defines the action.
/// </param>
/// <returns>
/// The value action.
/// </returns>
public override bool Deserialize(XElement xml)
{
this.Start = xml.Attribute("start").ValueOrDefault();
this.End = xml.Attribute("end").ValueOrDefault();
return this.Start.HasValue() && this.End.HasValue();
}
示例13: SingleViolation
/// <summary>
/// Constructor for the xml file, that is stored in the .xls file
/// </summary>
/// <param name="element">The root XElement of the xml</param>
/// <param name="workbook">The current workbook</param>
public SingleViolation(XElement element, Workbook workbook)
: base(element, workbook)
{
this.severity = Decimal.Parse(element.Attribute(XName.Get("severity")).Value);
this.controlName = element.Attribute(XName.Get("controlname")).Value;
this.groupedViolation = Convert.ToBoolean(element.Attribute(XName.Get("groupedviolation")).Value);
}
示例14: Parse
internal override void Parse(XElement element)
{
// Search results have different pagination fields for some reason...
if (element.Name == "search")
{
Start = element.ElementAsInt("results-start");
End = element.ElementAsInt("results-end");
TotalItems = element.ElementAsInt("total-results");
return;
}
var startAttribute = element.Attribute("start");
var endAttribute = element.Attribute("end");
var totalAttribute = element.Attribute("total");
if (startAttribute != null &&
endAttribute != null &&
totalAttribute != null)
{
int start = 0, end = 0, total = 0;
int.TryParse(startAttribute.Value, out start);
int.TryParse(endAttribute.Value, out end);
int.TryParse(totalAttribute.Value, out total);
Start = start;
End = end;
TotalItems = total;
}
}
示例15: TranscriptionPhrase
/// <summary>
/// v3 serialization
/// </summary>
/// <param name="e"></param>
public TranscriptionPhrase(XElement e)
{
Elements = e.Attributes().ToDictionary(a => a.Name.ToString(), a => a.Value);
Elements.Remove("b");
Elements.Remove("e");
Elements.Remove("f");
this._phonetics = (e.Attribute("f") ?? EmptyAttribute).Value;
this._text = e.Value.Trim('\r', '\n');
if (e.Attribute("b") != null)
{
string val = e.Attribute("b").Value;
int ms;
if (int.TryParse(val, out ms))
{
Begin = TimeSpan.FromMilliseconds(ms);
}
else
Begin = XmlConvert.ToTimeSpan(val);
}
if (e.Attribute("e") != null)
{
string val = e.Attribute("e").Value;
int ms;
if (int.TryParse(val, out ms))
{
End = TimeSpan.FromMilliseconds(ms);
}
else
End = XmlConvert.ToTimeSpan(val);
}
}