當前位置: 首頁>>代碼示例>>C#>>正文


C# Linq.XAttribute類代碼示例

本文整理匯總了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;
        }
開發者ID:ahirugumi,項目名稱:CSharp-Study,代碼行數:35,代碼來源:MyXMLClass.cs

示例2: CreateInstance

        public static dynamic CreateInstance(XAttribute attribute)
        {
            Contract.Requires(attribute != null);
            Contract.Ensures(Contract.Result<object>() != null);

            return new DynamicXAttribute(attribute);
        }
開發者ID:SergeyTeplyakov,項目名稱:DynamicXml,代碼行數:7,代碼來源:DynamicXAttribute.cs

示例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;
        }
開發者ID:andresperezpayeras,項目名稱:epubfixer,代碼行數:32,代碼來源:frmSpineEdit.cs

示例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));
 }
開發者ID:Notalib,項目名稱:DSync,代碼行數:7,代碼來源:XmlUtils.cs

示例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));
 }
開發者ID:Notalib,項目名稱:DSync,代碼行數:7,代碼來源:DAISYUtils.cs

示例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;
 }
開發者ID:Dazmo,項目名稱:Terraria-Map-Editor,代碼行數:7,代碼來源:XMLBase.cs

示例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;
 }
開發者ID:apetrovskiy,項目名稱:STUPS,代碼行數:7,代碼來源:DefaultsLoader.cs

示例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();
		}
開發者ID:dfilarowski,項目名稱:artificial-neural-network,代碼行數:27,代碼來源:CandidateElimination.cs

示例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.
 }
開發者ID:pezs89,項目名稱:BrickBreaker_Wpf_old,代碼行數:34,代碼來源:DifficultySelection.xaml.cs

示例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;
        }
開發者ID:uwitec,項目名稱:O2O,代碼行數:12,代碼來源:StringExtensions.cs

示例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 + "'.");
 }
開發者ID:kimbirkelund,項目名稱:SekhmetSerialization,代碼行數:7,代碼來源:ActualTypeFromAttributeTypeConverter.cs

示例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))
            };
        }
開發者ID:roh85,項目名稱:vika,代碼行數:26,代碼來源:InspectCodeParser.cs

示例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);
		}
開發者ID:bbriggs,項目名稱:FieldWorks,代碼行數:37,代碼來源:DataMigration7000035.cs

示例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.
                }
            }
        }
開發者ID:Cireson,項目名稱:EntityFramework6,代碼行數:26,代碼來源:CopyAnnotatableElementCommand.cs

示例15: AddAttribute

        public static XElement AddAttribute(this XElement element, string name, object value)
        {
            var attribute = new XAttribute(name, value);
            element.Add(attribute);

            return element;
        }
開發者ID:kkalinowski,項目名稱:lib12,代碼行數:7,代碼來源:XmlExtensions.cs


注:本文中的System.Xml.Linq.XAttribute類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。