当前位置: 首页>>代码示例>>C#>>正文


C# XElement.SetValue方法代码示例

本文整理汇总了C#中System.Xml.Linq.XElement.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.SetValue方法的具体用法?C# XElement.SetValue怎么用?C# XElement.SetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Linq.XElement的用法示例。


在下文中一共展示了XElement.SetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FillXmlData

        /// <summary>
        /// Fills the XML data.
        /// </summary>
        /// <param name="xml">The XML.</param>
        protected override void FillXmlData(XElement xml)
        {
            base.FillXmlData(xml);

            xml.SetValue( nodeName_Event, this.Event);
            xml.SetValue( nodeName_EventKey, this.EventKey);
        }
开发者ID:supertigerzou,项目名称:TigerArtStudio,代码行数:11,代码来源:EventMessage.cs

示例2: ToXml

        XElement ToXml(string elementName, object o)
        {
            if (o == null) o = new { };

            var result = new XElement(XmlConvert.EncodeName(elementName));

            if (IsPrimitive(o))
            {
                result.SetValue(o);

                return result;
            }

            if (o is IEnumerable)
            {
                foreach (var item in o as IEnumerable) result.Add(ToXml("item", item));

                return result;
            }

            var properties = o.GetType().GetProperties();

            foreach (var property in properties) result.Add(ToXml(property.Name, property.GetValue(o, null)));

            return result;
        }
开发者ID:adamjmoon,项目名称:Restful,代码行数:26,代码来源:xml.cs

示例3: AddCreateTranslationsTranslation

        private bool AddCreateTranslationsTranslation()
        {
            var translationsFilePath = GetTranslationFilePathPath();
            var translationsFile = XDocument.Load(translationsFilePath, LoadOptions.PreserveWhitespace);
            var success = true;
            try
            {
                var actions = translationsFile.XPathSelectElements(XPathQueryXmlTranslationActionArea).Single();
                if (!actions.XPathSelectElements(XPathQueryXmlCreateTranslationsKey).Any())
                {
                    var translation = new XElement("key", new XAttribute("alias", "polyglotCreateTranslations"));
                    translation.SetValue("Create translations");
                    actions.Add(translation);
                }
            }
            catch (Exception)
            {
                success = false;
            }

            if (success)
            {
                try
                {
                    translationsFile.Save(translationsFilePath, SaveOptions.DisableFormatting);
                }
                catch (Exception)
                {
                    success = false;
                }
            }

            return success;
        }
开发者ID:purna,项目名称:Polyglot,代码行数:34,代码来源:InstallAction.cs

示例4: EncodeXml

        public void EncodeXml(XElement root)
        {
            var attr = root.Attribute("Protected");
            if (attr != null && Convert.ToBoolean(attr.Value))
            {
                var protectedStringBytes = UTF8Encoding.UTF8.GetBytes(root.Value);
                int protectedByteLength = protectedStringBytes.Length;


                var cipher = cryptoRandomStream.GetRandomBytes((uint)protectedByteLength);
                byte[] pbPlain = new byte[protectedStringBytes.Length];


                for (int i = 0; i < pbPlain.Length; ++i)
                    pbPlain[i] = (byte)(protectedStringBytes[i] ^ cipher[i]);

                string mypass = Convert.ToBase64String(pbPlain);
                root.SetValue(mypass);
            }

            foreach (var node in root.Elements())
            {
                EncodeXml(node);
            }
        }
开发者ID:TheAngryByrd,项目名称:MetroPass,代码行数:25,代码来源:Kdb4Persister.cs

示例5: AddToElement

        public void AddToElement(SXL.XElement parent)
        {
            var prop_el = Internal.XMLUtil.CreateVisioSchema2003Element("Prop");
            if (this.Name != null)
            {
                prop_el.SetElementValue("Name", this.Name);
            }

            prop_el.SetAttributeValue("NameU", this.NameU);
            prop_el.SetAttributeValue("ID", this.ID);
            prop_el.SetElementValueConditional("Del", this._del);

            if (this.Value!=null)
            {
                var val_el = new SXL.XElement(Internal.Constants.VisioXmlNamespace2003 + "Value");
                prop_el.Add(val_el);
                val_el.SetAttributeValue("Unit", "STR");
                val_el.SetValue(this.Value);                
            }
            prop_el.Add(this.Prompt.ToXml("Prompt"));
            prop_el.Add(this.Label.ToXml("Label"));
            prop_el.Add(this.Format.ToXml("Format"));
            prop_el.Add(this.SortKey.ToXml("SortKey"));
            prop_el.Add(this.Type.ToXml("Type"));
            prop_el.Add(this.Invisible.ToXml("Invisible"));
            prop_el.Add(this.LangID.ToXml("LangID"));
            prop_el.Add(this.Calendar.ToXml("Calendar"));
            parent.Add(prop_el);
        }
开发者ID:Core2D,项目名称:VisioAutomation.VDX,代码行数:29,代码来源:CustomProp.cs

示例6: Generate

        public XElement Generate(TestCase testCase)
        {
            XElement main = new XElement("div");

            XElement tr = new XElement("tr");
            XElement tdName = new XElement("td", testCase.Desription);
            XElement tdStatus = new XElement("td", testCase.Result);
            XElement tdTime = new XElement("td", testCase.Time);

            XElement trMessage = new XElement("tr");
            XElement tdMessage = new XElement("td");


            if (testCase.Message != null || testCase.StackTrace != null)
            {
                XElement preMessage = new XElement("pre", testCase.Message);
                XElement preStackTrace = new XElement("pre", testCase.StackTrace);
                tdMessage.SetValue("MESSAGE:\n");

                tdMessage.Add(preMessage);
                tdMessage.Add(preStackTrace);
                trMessage.Add(tdMessage);
            }
            else if (!string.IsNullOrEmpty(testCase.Reason))
            {
                XElement reasonMessage = new XElement("pre", testCase.Reason);
                tdMessage.Add(reasonMessage);
                trMessage.Add(tdMessage);
            }

            tr.Add(tdName);
            tr.Add(tdStatus);
            tr.Add(tdTime);

            main.Add(tr);
            main.Add(trMessage);

            tdName.SetAttributeValue("style", "text-align:left;");
            trMessage.SetAttributeValue("style", "font-size:11px; text-align:left;");
            trMessage.SetAttributeValue("bgcolor", "lightgrey");
            tdMessage.SetAttributeValue("colspan", "3");


            switch (testCase.Result)
            {
                case "Success":
                    tdStatus.SetAttributeValue("bgcolor", "green");
                    break;
                case "Ignored":
                    tdStatus.SetAttributeValue("bgcolor", "yellow");
                    break;
                case "Failure":
                    tdStatus.SetAttributeValue("bgcolor", "red");
                    break;
                default:
                    break;
            }

            return main;
        }
开发者ID:IIITanbI,项目名称:OnlinerTests,代码行数:60,代码来源:Program.cs

示例7: Serialize

        protected override string Serialize(IDictionary<string, Dictionary<string, string>> data)
        {
            XDocument xml = new XDocument(new XElement(RootName));

            foreach (KeyValuePair<string, Dictionary<string, string>> sectionAndKeys in data)
            {
                string sectionName = sectionAndKeys.Key;
                var keys = sectionAndKeys.Value;

                if (keys.Any())
                {
                    XElement section = new XElement(SectionElementName);
                    section.SetAttributeValue(AttributeName, sectionName);

                    foreach (KeyValuePair<string, string> keyAndValue in keys)
                    {
                        string keyName = keyAndValue.Key;
                        string value = keyAndValue.Value;

                        XElement key = new XElement(KeyElementName);
                        key.SetAttributeValue(AttributeName, keyName);
                        key.SetValue(value);

                        section.Add(key);
                    }

                    xml.Root.Add(section);
                }
            }

            string output = this.OutputXml(xml);

            return output;
        }
开发者ID:HristoKolev,项目名称:NetInfrastructure,代码行数:34,代码来源:XmlDocument.cs

示例8: GetRequestContent

		private static byte[] GetRequestContent(String username, String password, String application, String accessKey, String privateAccessKey, Encoding encoding)
		{
			XDocument document = new XDocument(new XDeclaration("1.0", encoding.BodyName, "yes"));
			XElement root = new XElement("appAuthorization");

			XElement userNameElement = new XElement("username");
			userNameElement.SetValue(username);
			root.Add(userNameElement);

			XElement passwordElement = new XElement("password");
			passwordElement.SetValue(password);
			root.Add(passwordElement);

			XElement appElement = new XElement("application");
			appElement.SetValue(application);
			root.Add(appElement);

			XElement accessKeyElement = new XElement("accessKeyId");
			accessKeyElement.SetValue(accessKey);
			root.Add(accessKeyElement);

			XElement privateAccessKeyElement = new XElement("privateAccessKey");
			privateAccessKeyElement.SetValue(privateAccessKey);
			root.Add(privateAccessKeyElement);


			document.Add(root);
			return document.Encode(encoding);
		}
开发者ID:cloudguy,项目名称:sugarsync-.net-api,代码行数:29,代码来源:RefreshTokenRequest.cs

示例9: Execute

        public void Execute()
        {
            //
            // 親要素を持たない要素を作成し、特定のXMLツリーの中に組み込む. (アタッチ)
            //
            var noParent = new XElement("NoParent", true);
            var tree1 = new XElement("Parent", noParent);

            var noParent2 = tree1.Element("NoParent");
            Output.WriteLine("参照が同じ? = {0}", noParent == noParent2);
            Output.WriteLine(tree1);

            // 値を変更して確認.
            noParent.SetValue(false);
            Output.WriteLine(noParent.Value);
            Output.WriteLine(tree1.Element("NoParent")?.Value);

            Output.WriteLine("==========================================");

            //
            // 親要素を持つ要素を作成し、特定のXMLツリーの中に組み込む. (クローン)
            //
            var origTree = new XElement("Parent", new XElement("WithParent", true));
            var tree2 = new XElement("Parent", origTree.Element("WithParent"));

            Output.WriteLine("参照が同じ? = {0}", origTree.Element("WithParent") == tree2.Element("WithParent"));
            Output.WriteLine(tree2);

            // 値を変更して確認
            origTree.Element("WithParent")?.SetValue(false);
            Output.WriteLine(origTree.Element("WithParent")?.Value);
            Output.WriteLine(tree2.Element("WithParent")?.Value);
        }
开发者ID:devlights,项目名称:Sazare,代码行数:33,代码来源:LinqSamples58.cs

示例10: AddField

 private static void AddField(XElement doc, string name, string value)
 {
     var x = new XElement("field");
     x.SetAttributeValue("name", name);
     x.SetValue(value);
     doc.Add(x);
 }
开发者ID:NTCoding,项目名称:SolrIndexingSpike,代码行数:7,代码来源:SolrConverter.cs

示例11: CheckDate

        public ActionResult CheckDate(string app_id, string client_id)
        {
            XElement root;
            int appid = utility_functions.getAppID(app_id);

            if (appid == 0)
            {
                root = new XElement("error");
                root.SetValue("No such app - " + app_id);
                return new XmlResult(root);
            }

            DateTime eventdate = eventmodel.getLastEventUpdate(appid);
            DateTime messagedate = messagemodel.getLastMessageUpdate(appid);
            DateTime homescreendate = utility_functions.getHomeScreenUpdate(appid);
            root = new XElement("items");
            XElement messagenode = new XElement("messages");
            XElement eventnode = new XElement("events");
            XElement homenode = new XElement("hometext");

            messagenode.SetValue(messagedate.ToString("yyyy-MM-dd HH:mm:ss"));
            eventnode.SetValue(eventdate.ToString("yyyy-MM-dd HH:mm:ss"));
            homenode.SetValue(homescreendate.ToString("yyyy-MM-dd HH:mm:ss"));
            root.Add(eventnode);
            root.Add(messagenode);
            root.Add(homenode);

            utility_functions.insertServerEvent("date checked", app_id, client_id, Request.RawUrl, Request.UserHostAddress);

            return new XmlResult(root);
        }
开发者ID:alexaylwin,项目名称:campsoc,代码行数:31,代码来源:AppServiceController.cs

示例12: GenerateXml

        /// <summary>
        /// The generate xml.
        /// </summary>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string GenerateXml(IContent page)
        {
            if (page == null)
            {
                return string.Empty;
            }

            XDocument xDocument = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new object[0]);

            XElement xElement = new XElement("content");
            xElement.SetAttributeValue("name", XmlConvert.EncodeName(page.Name));

            List<KeyValuePair<string, string>> propertyValues = page.GetPropertyValues();

            foreach (KeyValuePair<string, string> content in propertyValues)
            {
                XElement xElement3 = new XElement(XmlConvert.EncodeName(content.Key));
                xElement3.SetValue(TextIndexer.StripHtml(content.Value, content.Value.Length));
                xElement.Add(xElement3);
            }

            xDocument.Add(xElement);

            return xDocument.ToString();
        }
开发者ID:jstemerdink,项目名称:EPiServer.Libraries,代码行数:34,代码来源:XmlOutputFormat.cs

示例13: Sync

		public void Sync(string pathSource, string pathTarget, string relative)
		{
			var source = XDocument.Load(pathSource);
			var target = XDocument.Load(pathTarget);

			var targetGroup = GutTarget(target);
			if (targetGroup == null)
				return;

			var sourceFiles = source.XPathSelectElements("//msbuild:ItemGroup/msbuild:Compile", _namespaceManager);
			foreach (var sourceFile in sourceFiles)
			{
				var attrInclude = sourceFile.Attribute(XName.Get("Include"));
				if (attrInclude == null) continue;
				if (attrInclude.Value.StartsWith(@"Properties\")) continue;

				var newIncludeText = relative + attrInclude.Value;
				var newLinkText = attrInclude.Value;

				var compileElement = new XElement(_ns + "Compile");
				compileElement.SetAttributeValue("Include", newIncludeText);
				var linkElement = new XElement(_ns + "Link");
				;
				linkElement.SetValue(newLinkText);

				compileElement.Add(linkElement);
				targetGroup.Add(compileElement);
			}

            target.Save(pathTarget);
		}
开发者ID:DevOpsGear,项目名称:DeployerOfCodes,代码行数:31,代码来源:ProjectSynchronizer.cs

示例14: createData

        internal static XElement createData(String _elename, String _dataitem_name, String _dataitem_subType, String _dataItem_id, XElement data)
        {
            String timestamp = data.Attribute("timestamp").Value;
            String sequence = data.Attribute("sequence").Value;
            XElement re = new XElement(MTConnectNameSpace.mtStreams + _elename, new XAttribute("name", _dataitem_name), new XAttribute("timestamp", timestamp), new XAttribute("sequence", sequence));
            re.Add(new XAttribute("dataItemId", _dataItem_id));
            if (_dataitem_subType != null)
                re.Add(new XAttribute("subType", _dataitem_subType));
            XAttribute temp = data.Attribute("partId");
            if ( temp != null )
                re.Add(new XAttribute("partId",temp.Value));
            temp = data.Attribute("workPieceId");
            if ( temp != null )
                re.Add(new XAttribute("workPieceId", temp.Value));
            temp = data.Attribute("state");
            if (temp != null)
                re.Add(new XAttribute("state", temp.Value));
            temp = data.Attribute("code");
            if (temp != null)
                re.Add(new XAttribute("code", temp.Value));
            temp = data.Attribute("severity");
            if (temp != null)
                re.Add(new XAttribute("severity", temp.Value));
            temp = data.Attribute("nativeCode");
            if (temp != null)
                re.Add(new XAttribute("nativeCode", temp.Value));

            re.SetValue(data.Value);
            return re;
        }
开发者ID:Wolfury,项目名称:MTConnect4OPC,代码行数:30,代码来源:DataUtil.cs

示例15: InstallDashboard

        // Partially taken from https://github.com/kipusoep/UrlTracker/blob/b2bc998adaae2f74779e1119fd7b1e97a3b71ed2/UI/Installer/UrlTrackerInstallerService.asmx.cs

        public static bool InstallDashboard(string section, string caption, string control)
        {
            bool result = false;
            try
            {
                string dashboardConfig;
                string dashboardConfigPath = HttpContext.Current.Server.MapPath("~/config/dashboard.config");
                using (StreamReader streamReader = File.OpenText(dashboardConfigPath))
                    dashboardConfig = streamReader.ReadToEnd();
                if (string.IsNullOrEmpty(dashboardConfig))
                    throw new Exception("Unable to add dashboard: Couldn't read current ~/config/dashboard.config, permissions issue?");
                XDocument dashboardDoc = XDocument.Parse(dashboardConfig, LoadOptions.PreserveWhitespace);
                if (dashboardDoc == null)
                    throw new Exception("Unable to add dashboard: Unable to parse current ~/config/dashboard.config file, invalid XML?");
                XElement dashBoardElement = dashboardDoc.Element("dashBoard");
                if (dashBoardElement == null)
                    throw new Exception("Unable to add dashboard: dashBoard element not found in ~/config/dashboard.config file");
                List<XElement> sectionElements = dashBoardElement.Elements("section").ToList();
                if (sectionElements == null || !sectionElements.Any())
                    throw new Exception("Unable to add dashboard: No section elements found in ~/config/dashboard.config file");
                XElement existingSectionElement = sectionElements.SingleOrDefault(x => x.Attribute("alias") != null && x.Attribute("alias").Value == section);
                if (existingSectionElement == null)
                    throw new Exception(string.Format("Unable to add dashboard: '{0}' section not found in ~/config/dashboard.config", section));

                List<XElement> tabs = existingSectionElement.Elements("tab").ToList();
                if (!tabs.Any())
                    throw new Exception(string.Format("Unable to add dashboard: No existing tabs found within the '{0}' section", section));

                List<XElement> existingTabs = tabs.Where(x => x.Attribute("caption").Value == caption).ToList();
                if (existingTabs.Any())
                {
                    foreach (XElement tab in existingTabs)
                    {
                        List<XElement> existingTabControls = tab.Elements("control").ToList();
                        if (existingTabControls.Any(x => x.Value == control))
                            return true;
                    }
                }

                XElement lastTab = tabs.Last();
                XElement newTab = new XElement("tab");
                newTab.Add(new XAttribute("caption", caption));
                XElement newControl = new XElement("control");
                newControl.Add(new XAttribute("addPanel", true));
                newControl.SetValue(control);
                newTab.Add(newControl);
                newControl.AddBeforeSelf(string.Concat(Environment.NewLine, "      "));
                newControl.AddAfterSelf(string.Concat(Environment.NewLine, "    "));
                lastTab.AddAfterSelf(newTab);
                lastTab.AddAfterSelf(string.Concat(Environment.NewLine, "    "));
                dashboardDoc.Save(dashboardConfigPath, SaveOptions.None);
                result = true;
            }
            catch (Exception ex)
            {
                ExceptionHelper.LogExceptionMessage(typeof(DashboardHelper), ex);
            }
            return result;
        }
开发者ID:AffinityID,项目名称:BackofficeTweaking,代码行数:61,代码来源:DashboardHelper.cs


注:本文中的System.Xml.Linq.XElement.SetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。