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


C# XAttribute.Remove方法代码示例

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


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

示例1: ChangeNamespaceDeclaration

        /// <summary>
        /// Changes the prefix or URI of a namespace declaration. This is non-trivial since XAttribute does not support this by default.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="oldDec"></param>
        /// <param name="parrent"></param>
        /// <param name="newUri"></param>
        /// <param name="newPrefix"></param>
        /// <returns></returns>
        public XAttribute ChangeNamespaceDeclaration(XDocument doc, XAttribute oldDec, XElement parrent, string newUri, string newPrefix)
        {
            ChangeNamespace(oldDec.Name.LocalName, oldDec.Value, newPrefix, newUri);

            string oldNamespace = oldDec.Value;
            oldDec.Remove();

            newPrefix = newPrefix.Replace("xmlns:", "");
            XAttribute newAttribute = new XAttribute(XNamespace.Xmlns + newPrefix, newUri);

            parrent.Add(newAttribute);

            foreach (XElement element in doc.Elements())
            {
                ChangeNamespaceForElement(element, oldNamespace, newUri);
            }

            return newAttribute;
        }
开发者ID:steffan88,项目名称:XmlEditor,代码行数:28,代码来源:NamespaceManager.cs

示例2: OwningSequencePropertyHasCorrectResponses

		public void OwningSequencePropertyHasCorrectResponses()
		{
			var element = new XElement("CmPossibility", new XAttribute(SharedConstants.GuidStr, "c1ee310c-e382-11de-8a39-0800200c9a66"));
			AddBasicPropertyElementsToPoss(element);
			var prop = new XElement("SubPossibilities");
			element.Add(prop);

			var extraAttr = new XAttribute("bogus", "badvalue");
			prop.Add(extraAttr);
			var result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Has unrecognized attribute(s)"));
			extraAttr.Remove();

			// No children is fine.
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNull(result);

			var extraChild = new XElement("BogusChild");
			prop.Add(extraChild);
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Contains unrecognized child elements"));
			extraChild.Remove();
		}
开发者ID:gmartin7,项目名称:flexbridge,代码行数:25,代码来源:CmObjectValidatorTests.cs

示例3: OwningAtomicPropertyHasCorrectResponses

		public void OwningAtomicPropertyHasCorrectResponses()
		{
			var element = new XElement("CmPossibility", new XAttribute(SharedConstants.GuidStr, "c1ee3109-e382-11de-8a39-0800200c9a66"));
			AddBasicPropertyElementsToPoss(element);
			var prop = new XElement("Discussion");
			element.Add(prop);

			var extraAttr = new XAttribute("bogus", "badvalue");
			prop.Add(extraAttr);
			var result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Has unrecognized attribute(s)"));
			extraAttr.Remove();

			var stText1 = new XElement("StText", new XAttribute(SharedConstants.GuidStr, "c1ee310a-e382-11de-8a39-0800200c9a66"), new XElement("DateModified", new XAttribute(SharedConstants.Val, "2013-1-1 19:39:28.829")), new XElement("RightToLeft", new XAttribute(SharedConstants.Val, "True")));
			prop.Add(stText1);
			var stText2 = new XElement("StText", new XAttribute(SharedConstants.GuidStr, "c1ee310b-e382-11de-8a39-0800200c9a66"), new XElement("DateModified", new XAttribute(SharedConstants.Val, "2013-1-1 19:39:28.829")), new XElement("RightToLeft", new XAttribute(SharedConstants.Val, "True")));
			prop.Add(stText2);
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Has too many child elements"));
			stText2.Remove();

			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNull(result);

			stText1.Attribute(SharedConstants.GuidStr).Remove();
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("No guid attribute"));
		}
开发者ID:gmartin7,项目名称:flexbridge,代码行数:31,代码来源:CmObjectValidatorTests.cs

示例4: ReferenceCollectionPropertyHasCorrectResponses

		public void ReferenceCollectionPropertyHasCorrectResponses()
		{
			var element = new XElement("CmPossibility", new XAttribute(SharedConstants.GuidStr, "c1ee3106-e382-11de-8a39-0800200c9a66"));
			AddBasicPropertyElementsToPoss(element);
			var prop = new XElement("Restrictions");
			element.Add(prop);

			var extraAttr = new XAttribute("bogus", "badvalue");
			prop.Add(extraAttr);
			var result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Has unrecognized attribute(s)"));
			extraAttr.Remove();

			var extraChild = new XElement("BogusChild");
			prop.Add(extraChild);
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Contains child elements that are not 'refcol'"));
			extraChild.Remove();

			var refcol1 = new XElement(SharedConstants.Refcol, new XAttribute(SharedConstants.GuidStr, "c1ee3107-e382-11de-8a39-0800200c9a66"),
									   new XAttribute("t", "r"));
			var refcol2 = new XElement(SharedConstants.Refcol, new XAttribute(SharedConstants.GuidStr, "c1ee3108-e382-11de-8a39-0800200c9a66"),
									   new XAttribute("t", "r"));
			prop.Add(refcol1);
			prop.Add(refcol2);
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNull(result);
		}
开发者ID:gmartin7,项目名称:flexbridge,代码行数:30,代码来源:CmObjectValidatorTests.cs

示例5: ReferenceSequencePropertyHasCorrectResponses

		public void ReferenceSequencePropertyHasCorrectResponses()
		{
			var element = new XElement("Segment", new XAttribute(SharedConstants.GuidStr, "c1ee3103-e382-11de-8a39-0800200c9a66"), new XElement("BeginOffset", new XAttribute(SharedConstants.Val, 1)));
			var prop = new XElement("Analyses");
			element.Add(prop);

			var extraAttr = new XAttribute("bogus", "badvalue");
			prop.Add(extraAttr);
			var result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Has unrecognized attribute(s)"));
			extraAttr.Remove();

			var extraChild = new XElement("BogusChild");
			prop.Add(extraChild);
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Contains child elements that are not 'refseq'"));
			extraChild.Remove();

			var refseq1 = new XElement(SharedConstants.Refseq, new XAttribute(SharedConstants.GuidStr, "c1ee3104-e382-11de-8a39-0800200c9a66"),
									   new XAttribute("t", "r"));
			var refseq2 = new XElement(SharedConstants.Refseq, new XAttribute(SharedConstants.GuidStr, "c1ee3105-e382-11de-8a39-0800200c9a66"),
									   new XAttribute("t", "r"));
			prop.Add(refseq1);
			prop.Add(refseq2);
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNull(result);
		}
开发者ID:gmartin7,项目名称:flexbridge,代码行数:29,代码来源:CmObjectValidatorTests.cs

示例6: ReferenceAtomicPropertyHasCorrectResponses

		public void ReferenceAtomicPropertyHasCorrectResponses()
		{
			var element = new XElement("CmPossibility", new XAttribute(SharedConstants.GuidStr, "c1ee3102-e382-11de-8a39-0800200c9a66"));
			AddBasicPropertyElementsToPoss(element);
			var prop = new XElement("Confidence");
			element.Add(prop);
			var objsurElement = new XElement(SharedConstants.Objsur);
			prop.Add(objsurElement);
			const string guidValue = "c1ee3113-e382-11de-8a39-0800200c9a66";
			var guidAttr = new XAttribute(SharedConstants.GuidStr, guidValue);
			var typeAttr = new XAttribute("t", "r");
			objsurElement.Add(guidAttr);
			objsurElement.Add(typeAttr);

			var result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNull(result);

			var extraAttr = new XAttribute("bogus", "badvalue");
			prop.Add(extraAttr);
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Has unrecognized attribute(s)"));

			extraAttr.Remove();
			objsurElement.Add(extraAttr);
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Has too many attributes"));
			extraAttr.Remove();

			var extraChild = new XElement("BogusChild");
			objsurElement.Add(extraChild);
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("'objsur' element has child element(s)"));
			extraChild.Remove();

			prop.Add(extraChild);
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Has too many child elements"));
			extraChild.Remove();

			guidAttr.Value = "badValue";
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			guidAttr.Value = guidValue;

			guidAttr.Remove();
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			objsurElement.Add(guidAttr);

			typeAttr.Value = "o";
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			typeAttr.Value = "r";

			typeAttr.Remove();
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
		}
开发者ID:gmartin7,项目名称:flexbridge,代码行数:62,代码来源:CmObjectValidatorTests.cs

示例7: MultiStringHasCorrectRepsonses

		public void MultiStringHasCorrectRepsonses()
		{
			const string str = @"<CmPossibilityList
						guid='cf379f73-9ee5-4e45-b2e2-4b169666d83e'>
		<Description>
			<AStr
				ws='en'>
				<Run
					ws='en'>English multi-string description.</Run>
			</AStr>
			<AStr
				ws='es'>
				<Run
					ws='es'>Spanish multi-string description.</Run>
			</AStr>
		</Description>
						</CmPossibilityList>";
			var element = XElement.Parse(str);
			AddBasicPropertyElementsToPossList(element);
			var result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNull(result);

			var badAttr = new XAttribute("bogusAttr", "badvalue");
			element.Element("Description").Add(badAttr);
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Has unrecognized attribute(s)"));
			badAttr.Remove();

			var extraChild = new XElement("extraChild");
			element.Element("Description").Add(extraChild);
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Has non-AStr child element"));
			extraChild.Remove();

			// Test the <Run> element.
			var runElement = element.Element("Description").Element("AStr").Element("Run");
			runElement.Add(extraChild);
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Has non-text child element"));
			extraChild.Remove();

			runElement.Add(badAttr);
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Invalid attribute for <Run> element"));
			badAttr.Remove();
		}
开发者ID:gmartin7,项目名称:flexbridge,代码行数:50,代码来源:CmObjectValidatorTests.cs

示例8: AttributeRemove

        public void AttributeRemove()
        {
            XElement e = new XElement("element");
            XAttribute a = new XAttribute("attribute", "value");

            // Can't remove when no parent.
            Assert.Throws<InvalidOperationException>(() => a.Remove());

            e.Add(a);
            Assert.Equal(1, e.Attributes().Count());

            a.Remove();
            Assert.Empty(e.Attributes());
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:14,代码来源:SDMAttribute.cs

示例9: RemoveStandaloneAttribute

        //[Variation(Priority = 2, Desc = "Remove standalone attribute - def namespace", Params = new object[] { "xmlns", "value" })]
        //[Variation(Priority = 2, Desc = "Remove standalone attribute - namespace", Params = new object[] { "{http://www.w3.org/2000/xmlns/}p", "value" })]
        //[Variation(Priority = 2, Desc = "Remove standalone attribute I.", Params = new object[] { "{a}aa", "value" })]
        //[Variation(Priority = 2, Desc = "Remove standalone attribute II.", Params = new object[] { "aa", "value" })]
        public void RemoveStandaloneAttribute()
        {
            _runWithEvents = (bool)Params[0];
            var name = (string)Variation.Params[0];
            var value = (string)Variation.Params[1];
            var a = new XAttribute(name, value);

            try
            {
                if (_runWithEvents)
                {
                    _eHelper = new EventsHelper(a);
                }
                a.Remove();
                if (_runWithEvents)
                {
                    _eHelper.Verify(XObjectChange.Remove, a);
                }
                TestLog.Compare(false, "Exception was expected here");
            }
            catch (InvalidOperationException)
            {
                // Expected exception
            }
            a.Verify();
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:30,代码来源:XAttributeRemove.cs

示例10: XAttribute

        public new CSSStyleRuleMonkier this[Task task]
        {
            // x:\jsc.svn\examples\javascript\async\asyncworkersourcesha1\asyncworkersourcesha1\application.cs

            get
            {

                //var TaskIdentity = new Random().Next();
                var TaskName = "incomplete";

                if (InternalTaskNameLookup.ContainsKey(task))
                {
                    TaskName = InternalTaskNameLookup[task];
                }

                InternalTaskIdentity++;
                var a = new XAttribute("await" + InternalTaskIdentity, TaskName);


                var s = this.selectorElement;
                var p = this;

                while (p != null)
                {
                    if (p.selectorElement != null)
                    {
                        s = p.selectorElement;

                        break;
                    }
                    p = this.parent;
                }

                a.AttachTo(s);

                var x = !this[a];
                // when complete
                x.__task = task;


                // overkill
                Native.window.onframe +=
                    delegate
                    {
                        if (a == null)
                            return;

                        if (task.IsCompleted)
                        {
                            if (InternalTaskNameLookup.ContainsKey(task))
                                InternalTaskNameLookup.Remove(task);


                            a.Remove();

                            a = null;
                        }
                    };

                // how should we be introducing the conditional? document level?

                return x;
            }

        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:65,代码来源:CSSStyleRule.cs

示例11: AttributeRemove

                /// <summary>
                /// Validates the behavior of the Remove method on XAttribute.
                /// </summary>
                /// <returns>true if pass, false if fail</returns>
                //[Variation(Desc = "AttributeRemove")]
                public void AttributeRemove()
                {
                    XElement e = new XElement("element");
                    XAttribute a = new XAttribute("attribute", "value");

                    // Can't remove when no parent.
                    try
                    {
                        a.Remove();
                        Validate.ExpectedThrow(typeof(InvalidOperationException));
                    }
                    catch (Exception ex)
                    {
                        Validate.Catch(ex, typeof(InvalidOperationException));
                    }

                    e.Add(a);
                    Validate.Count(e.Attributes(), 1);

                    a.Remove();
                    Validate.Count(e.Attributes(), 0);
                }
开发者ID:johnhhm,项目名称:corefx,代码行数:27,代码来源:SDMAttribute.cs

示例12: XElementChangeAttributesParentInThePreEventHandler

        public void XElementChangeAttributesParentInThePreEventHandler()
        {
            bool firstTime = true;
            XElement element = XElement.Parse("<root></root>");
            XAttribute child = new XAttribute("Add", "Me");
            element.Add(child);
            element.Changing += new EventHandler<XObjectChangeEventArgs>(
                delegate (object sender, XObjectChangeEventArgs e)
                {
                    if (firstTime)
                    {
                        firstTime = false;
                        child.Remove();
                    }
                });

            Assert.Throws<InvalidOperationException>(() => { child.Remove(); });
            element.Verify();
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:19,代码来源:EventsRemove.cs

示例13: FixUpEntityTypeMapping

		private static void FixUpEntityTypeMapping(
				XAttribute storeEntitySetAttribute, XElement entityTypeMappingNode)
		{
			XName xn = XName.Get("MappingFragment", entityTypeMappingNode.Name.NamespaceName);
			XElement mf = new XElement(xn);

			// move the StoreEntitySet attribute into this node
			storeEntitySetAttribute.Remove();
			mf.Add(storeEntitySetAttribute);

			// now move all descendants into this node
			ReparentChildren(entityTypeMappingNode, mf);

			entityTypeMappingNode.Add(mf);
		}
开发者ID:nHydrate,项目名称:nHydrate,代码行数:15,代码来源:EdmGen2.cs

示例14: FixUpEntitySetMapping

		private static void FixUpEntitySetMapping(
				XAttribute typeNameAttribute, XElement entitySetMappingNode)
		{
			XName xn = XName.Get("EntityTypeMapping", entitySetMappingNode.Name.NamespaceName);

			typeNameAttribute.Remove();
			XElement etm = new XElement(xn);
			etm.Add(typeNameAttribute);

			// move the "storeEntitySet" attribute into the new 
			// EntityTypeMapping node
			foreach (XAttribute a in entitySetMappingNode.Attributes())
			{
				if (a.Name.LocalName == "StoreEntitySet")
				{
					a.Remove();
					etm.Add(a);
					break;
				}
			}

			// now move all descendants into this node
			ReparentChildren(entitySetMappingNode, etm);

			entitySetMappingNode.Add(etm);
		}
开发者ID:nHydrate,项目名称:nHydrate,代码行数:26,代码来源:EdmGen2.cs

示例15: OwningCollectionPropertyHasCorrectResponses

		public void OwningCollectionPropertyHasCorrectResponses()
		{
			var element = new XElement("StText", new XAttribute(SharedConstants.GuidStr, "c1ee310d-e382-11de-8a39-0800200c9a66"), new XElement("DateModified", new XAttribute(SharedConstants.Val, "2013-1-1 19:39:28.829")), new XElement("RightToLeft", new XAttribute(SharedConstants.Val, "True")));
			var prop = new XElement("Tags");
			element.Add(prop);

			// Owns col of TextTag

			var extraAttr = new XAttribute("bogus", "badvalue");
			prop.Add(extraAttr);
			var result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNotNull(result);
			Assert.IsTrue(result.Contains("Has unrecognized attribute(s)"));
			extraAttr.Remove();

			// No children is fine.
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNull(result);

			var ttElement1 = new XElement("TextTag", new XAttribute(SharedConstants.GuidStr, "c1ee310e-e382-11de-8a39-0800200c9a66"), new XElement("BeginAnalysisIndex", new XAttribute(SharedConstants.Val, 1)), new XElement("EndAnalysisIndex", new XAttribute(SharedConstants.Val, 1)));
			var ttElement2 = new XElement("TextTag", new XAttribute(SharedConstants.GuidStr, "c1ee310f-e382-11de-8a39-0800200c9a66"), new XElement("BeginAnalysisIndex", new XAttribute(SharedConstants.Val, 1)), new XElement("EndAnalysisIndex", new XAttribute(SharedConstants.Val, 1)));
			prop.Add(ttElement1);
			prop.Add(ttElement2);
			result = CmObjectValidator.ValidateObject(_mdc, element);
			Assert.IsNull(result);
		}
开发者ID:gmartin7,项目名称:flexbridge,代码行数:26,代码来源:CmObjectValidatorTests.cs


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