本文整理汇总了C#中System.Xml.Linq.XAttribute类的典型用法代码示例。如果您正苦于以下问题:C# XAttribute类的具体用法?C# XAttribute怎么用?C# XAttribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XAttribute类属于System.Xml.Linq命名空间,在下文中一共展示了XAttribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetXMLDocument
public XDocument GetXMLDocument()
{
var myxml = new XDocument ();
var myele = new XElement ("myxmls");
var ele100 = new XElement ("myxml");
var idele100 = new XElement ("id", "100");
var nameele100 = new XElement ("name", "hoge");
var mailatt100 = new XAttribute ("mail", "[email protected]");
myele.Add (ele100);
ele100.Add (idele100);
nameele100.Add (mailatt100);
ele100.Add (nameele100);
var ele200 = new XElement ("myxml");
var idele200 = new XElement ("id", "200");
var nameele200 = new XElement ("name", "bar");
var mailatt200 = new XAttribute ("mail", "[email protected]");
myele.Add (ele200);
ele200.Add (idele200);
nameele200.Add (mailatt200);
ele200.Add (nameele200);
var ele300 = new XElement ("myxml");
var idele300 = new XElement ("id", "300");
var nameele300 = new XElement ("name", "foo");
var mailatt300 = new XAttribute ("mail", "[email protected]");
myele.Add (ele300);
ele300.Add (idele300);
nameele300.Add (mailatt300);
ele300.Add (nameele300);
myxml.Add (myele);
return myxml;
}
示例2: CreateInstance
public static dynamic CreateInstance(XAttribute attribute)
{
Contract.Requires(attribute != null);
Contract.Ensures(Contract.Result<object>() != null);
return new DynamicXAttribute(attribute);
}
示例3: ExportNewTOC
protected override XElement ExportNewTOC()
{
List<XElement> list = new List<XElement>();
foreach (Node item in Model.Nodes)
{
XElement navPoint = ConvertToXElement(item);
if (navPoint != null)
{
list.Add(navPoint);
}
}
IEnumerable<XAttribute> spine = TOC.Attributes();
XElement navMap = null;
if (spine.Count()>0)
{
navMap = new XElement(ns + "spine", spine, list);
} else
{
//There is no spine elements
OpfDocument doc = new OpfDocument();
XAttribute TocRef = new XAttribute("toc", doc.GetNCXid());
navMap = new XElement(ns + "spine", TocRef, list);
}
OnSave(new ExportTocEventArgs(navMap));
//_NewTOC = navMap;
return navMap;
}
示例4: ParseSyncAttribute
public static long ParseSyncAttribute(XAttribute syncAttr)
{
if (syncAttr == null) throw new ArgumentNullException("syncAttr");
long res;
if (Int64.TryParse(syncAttr.Value, out res)) return res;
throw new XmlException(String.Format("Invalid synchronization attribute {0}", syncAttr));
}
示例5: ParseClipAttribute
public static TimeSpan ParseClipAttribute(XAttribute attr)
{
if (attr == null) throw new ArgumentNullException("attr");
var m = Regex.Match(attr.Value, @"^npt=(\d+(\.\d+)?)s$");
if (!m.Success) throw new ApplicationException("Clip attribute " + attr.Name + " has invalid value " + attr.Value);
return TimeSpan.FromSeconds(Double.Parse(m.Groups[1].Value, CultureInfo.InvariantCulture));
}
示例6: XMLConvert
public FrameDirection XMLConvert(FrameDirection v, XAttribute attr)
{
if (attr == null) return v;
FrameDirection f = FrameDirection.None;
f = f.Convert<FrameDirection>(attr);
return f;
}
示例7: SetWorkflowElement
void SetWorkflowElement(XDocument xDocument)
{
var workflowElement = xDocument.Descendants(LogicConstants.DefaultsLoader_Workflow).FirstOrDefault();
var defaultAttributeValue = new XAttribute(LogicConstants.DefaultsLoader_Workflow_Name, string.Empty);
if (null != workflowElement)
Defaults.Workflow = (workflowElement.Attribute(LogicConstants.DefaultsLoader_Workflow_Name) ?? defaultAttributeValue).Value;
}
示例8: CandidateElimination
public CandidateElimination(string fileName) : base(fileName) {
//setup current hypothesis
XName name = "row";
_currentHypothesis = new XElement(name);
XAttribute newAttribute = null;
_attributeList = new List<XName>();
//initialize the most specific hypothesis set
foreach (XAttribute a in _dataSet.SampleRowElement.Attributes()) {
newAttribute = new XAttribute(a.Name, "");
_attributeList.Add(a.Name);
_currentHypothesis.Add(newAttribute);
}
_specificHypotheses = new List<XElement>();
_specificHypotheses.Add(new XElement(_currentHypothesis));
//setup current hypothesis
_currentHypothesis = new XElement(name);
//initialize the most specific hypothesis set
foreach (XAttribute a in _dataSet.SampleRowElement.Attributes()) {
newAttribute = new XAttribute(a.Name, "Q");
_currentHypothesis.Add(newAttribute);
}
_generalHypotheses = new List<XElement>();
_generalHypotheses.Add(new XElement(_currentHypothesis));
_targetConcept = _attributeList[_attributeList.Count - 1];
eliminateCandidates();
}
示例9: CheckForFiles
/// <summary>
/// Checks if the files exist.
/// </summary>
private void CheckForFiles()
{
if (!File.Exists(@"..\..\Resources\OptionsSettings.xml"))
{
if (MessageBox.Show("Couldn't find the xml file for the settings. \n Would you like to create a new with default settings?", "Error", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
XElement mouseElement = new XElement("mouse", "true");
XElement keyboardElement = new XElement("keyboard", "true");
XElement soundElement = new XElement("sound", "true");
XElement resolutionElement = new XElement("resolution", "1024x768");
XElement leftkeyElement = new XElement("leftkey", "Left");
XElement rightkeyElement = new XElement("rightkey", "Right");
XElement firekeyElement = new XElement("firekey", "Space");
XElement pausekeyElement = new XElement("pausekey", "P");
XElement difficultyElement = new XElement("difficulty", "1");
XElement mapElement = new XElement("map", "1");
XAttribute newAttribute = new XAttribute("id", 1);
XElement newElements = new XElement("option", newAttribute, mouseElement, keyboardElement, soundElement, resolutionElement, leftkeyElement, rightkeyElement, firekeyElement, pausekeyElement, difficultyElement, mapElement);
XElement newOptions = new XElement("Options", newElements);
XDocument newDocument = new XDocument(newOptions);
newDocument.Save(@"..\..\Resources\OptionsSettings.xml");
}
else
{
MapSelection returnToMap = new MapSelection();
returnToMap.Show();
Close();
}
}
// If the OptionsSettings xml doesn't exist, then send message.
}
示例10: GetXAttributeValue
/// <summary>
/// Get XAttribute Value
/// </summary>
/// <param name="XAttribute">xAttribute</param>
/// <returns>Value</returns>
public static string GetXAttributeValue(XAttribute xAttribute)
{
if (xAttribute == null)
return string.Empty;
return xAttribute.Value;
}
示例11: LogResult
private static void LogResult(Type result, XAttribute attr)
{
if (result == null)
_log.Warn("Unable to load type from attribute named '" + attr.Name + "' with value '" + attr.Value + "'.");
else if (_log.IsDebugEnabled)
_log.Debug("Loaded type '" + result + "' from attribute named '" + attr.Name + "'.");
}
示例12: GetOffset
private Offset GetOffset(XAttribute offsetAttribute, string sourceFilePath, uint? lineNumber)
{
if (offsetAttribute == null || !_fileSystem.File.Exists(sourceFilePath))
{
return null;
}
string start = null;
string end = null;
var dashIndex = offsetAttribute.Value.IndexOf("-", StringComparison.OrdinalIgnoreCase);
if (dashIndex > -1)
{
start = offsetAttribute.Value.Substring(0, dashIndex);
end = offsetAttribute.Value.Substring(dashIndex + 1);
}
var lines = _fileSystem.File.ReadLines(sourceFilePath);
var issueLineOffset = lines.Take((int)lineNumber.Value - 1).Sum(line => line.Length);
return new Offset
{
Start = string.IsNullOrWhiteSpace(start) ? null : (uint?)(int.Parse(start) - (issueLineOffset + lineNumber.Value - 1)),
End = string.IsNullOrWhiteSpace(end) ? null : (uint?)(int.Parse(end) - (issueLineOffset + lineNumber.Value - 1))
};
}
示例13: PerformMigration
/// ------------------------------------------------------------------------------------
/// <summary>
/// Change any bogus non-owning footnote links in the vernacular (but NOT in the BT)
/// to be owning links
/// </summary>
/// <param name="domainObjectDtoRepository">
/// Repository of all CmObject DTOs available for one migration step.
/// </param>
/// ------------------------------------------------------------------------------------
public void PerformMigration(IDomainObjectDTORepository domainObjectDtoRepository)
{
DataMigrationServices.CheckVersionNumber(domainObjectDtoRepository, 7000034);
foreach (var scrTxtPara in domainObjectDtoRepository.AllInstancesSansSubclasses("ScrTxtPara"))
{
XElement para = XElement.Parse(scrTxtPara.Xml);
XElement contents = para.Element("Contents");
if (contents == null)
continue;
XElement str = contents.Element("Str");
if (str == null)
continue;
foreach (XElement run in str.Elements("Run"))
{
XAttribute linkAttr = run.Attribute("link");
if (linkAttr == null)
continue; // Run doesn't contain an unowned hot-link
XAttribute ownedLinkAttr = new XAttribute("ownlink", linkAttr.Value);
run.Add(ownedLinkAttr);
linkAttr.Remove();
DataMigrationServices.UpdateDTO(domainObjectDtoRepository, scrTxtPara, para.ToString());
}
}
DataMigrationServices.IncrementVersionNumber(domainObjectDtoRepository);
}
示例14: AddAnnotations
protected virtual void AddAnnotations(AnnotatableElementClipboardFormat clipboardFormat, EFElement element)
{
foreach (var t in clipboardFormat.AdditionalAttributes)
{
var name = t.Item1;
var value = t.Item2;
var xn = XName.Get(name);
var xa = new XAttribute(xn, value);
element.XElement.Add(xa);
}
foreach (var s in clipboardFormat.AdditionalElements)
{
try
{
var d = XDocument.Parse(s, LoadOptions.PreserveWhitespace);
var xe = d.Root;
xe.Remove();
element.XElement.Add(xe);
}
catch (XmlException)
{
// ignore an XmlException. There was probalby a problem parsing.
}
}
}
示例15: AddAttribute
public static XElement AddAttribute(this XElement element, string name, object value)
{
var attribute = new XAttribute(name, value);
element.Add(attribute);
return element;
}