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


C# XDocument.Nodes方法代码示例

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


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

示例1: VerifyRemoveNodes

        private void VerifyRemoveNodes(XDocument doc)
        {
            IEnumerable<XNode> nodesBefore = doc.Nodes().ToList();
            XDeclaration decl = doc.Declaration;

            doc.RemoveNodes();

            TestLog.Compare(doc.Nodes().IsEmpty(), "e.Nodes().IsEmpty()");
            TestLog.Compare(nodesBefore.Where(n => n.Parent != null).IsEmpty(), "nodesBefore.Where(n=>n.Parent!=null).IsEmpty()");
            TestLog.Compare(nodesBefore.Where(n => n.Document != null).IsEmpty(), "nodesBefore.Where(n=>n.Parent!=null).IsEmpty()");
            TestLog.Compare(doc.Declaration == decl, "doc.Declaration == decl");
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:12,代码来源:XContainerRemoveNodesOnXDocument.cs

示例2: Normalize

 public static XDocument Normalize(XDocument source, XmlSchemaSet schema)
 {
     bool havePSVI = false;
     // validate, throw errors, add PSVI information
     if (schema != null)
     {
         source.Validate(schema, null, true);
         havePSVI = true;
     }
     return new XDocument(
         source.Declaration,
         source.Nodes().Select(n =>
         {
             // Remove comments, processing instructions, and text nodes that are
             // children of XDocument.  Only white space text nodes are allowed as
             // children of a document, so we can remove all text nodes.
             if (n is XComment || n is XProcessingInstruction || n is XText)
                 return null;
             XElement e = n as XElement;
             if (e != null)
                 return NormalizeElement(e, havePSVI);
             return n;
         }
         )
     );
 }
开发者ID:mvlasenko,项目名称:TridionDesktopTools,代码行数:26,代码来源:MarkupSimplifier.cs

示例3: ConvertCloverXMLtoJSON

        private static void ConvertCloverXMLtoJSON(XDocument xdoc, CoverallsModelcs coverallsModelcs)
        {
            foreach (XElement projects in (xdoc.Nodes().First() as XElement).Nodes())
            {
                foreach (XElement file in projects.Nodes())
                {
                    if (file.Name == "file")
                    {
                        var sourceFileModel = new SourceFileModel();
                        sourceFileModel.Name = file.Attribute("name").Value;
                        var coverage = new PhpList();

                        foreach (XElement line in file.Nodes())
                        {
                            if (line.Name == "line")
                                coverage[Convert.ToInt32(line.Attribute("num").Value)] =
                                    Convert.ToInt32(line.Attribute("count").Value);
                            else
                            {
                                coverage.Normalize(Convert.ToInt32(line.Attribute("loc").Value));
                            }
                        }
                        sourceFileModel.SourceDigest = GetMd5(sourceFileModel.Name);
                        sourceFileModel.Name = ToRelativePath(sourceFileModel.Name);
                        sourceFileModel.Coverage = coverage;
                        coverallsModelcs.SourceFiles.Add(sourceFileModel);
                    }
                }
            }
        }
开发者ID:smad2005,项目名称:PhpCoveralls,代码行数:30,代码来源:Program.cs

示例4: Visit

        /// <summary>
        /// Invoked for each <see cref="XDocument"/>.
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        public virtual XDocument Visit(XDocument document)
        {
            Contract.Requires<ArgumentNullException>(document != null);

            return new XDocument(
                document.Declaration != null ? Visit(document.Declaration) : null,
                document.Nodes().Select(i => Visit((XObject)i)));
        }
开发者ID:nxkit,项目名称:nxkit,代码行数:13,代码来源:XTransformer.cs

示例5: CreateEmptyDocument

        public void CreateEmptyDocument()
        {
            XDocument doc = new XDocument();

            Assert.Null(doc.Parent);
            Assert.Null(doc.Root);
            Assert.Null(doc.Declaration);
            Assert.Empty(doc.Nodes());
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:9,代码来源:SDMDocument.cs

示例6: CreateEmptyDocument

                /// <summary>
                /// Validate behavior of the default XDocument constructor.
                /// </summary>
                /// <returns>true if pass, false if fail</returns>
                //[Variation(Desc = "CreateEmptyDocument")]
                public void CreateEmptyDocument()
                {
                    XDocument doc = new XDocument();

                    Validate.IsNull(doc.Parent);
                    Validate.IsNull(doc.Root);
                    Validate.IsNull(doc.Declaration);
                    Validate.Enumerator(doc.Nodes(), new XNode[0]);
                }
开发者ID:johnhhm,项目名称:corefx,代码行数:14,代码来源:SDMDocument.cs

示例7: Visit

        /// <summary>
        /// Invoked for each <see cref="XDocument"/>.
        /// </summary>
        /// <param name="document"></param>
        public virtual void Visit(XDocument document)
        {
            Contract.Requires<ArgumentNullException>(document != null);

            if (document.Declaration != null)
                Visit(document.Declaration);

            foreach (XObject node in document.Nodes())
                Visit(node);
        }
开发者ID:nxkit,项目名称:nxkit,代码行数:14,代码来源:XVisitor.cs

示例8: CreateDocumentWithContent

        public void CreateDocumentWithContent()
        {
            XDeclaration declaration = new XDeclaration("1.0", "utf-8", "yes");
            XComment comment = new XComment("This is a document");
            XProcessingInstruction instruction = new XProcessingInstruction("doc-target", "doc-data");
            XElement element = new XElement("RootElement");

            XDocument doc = new XDocument(declaration, comment, instruction, element);

            Assert.Equal(new XNode[] { comment, instruction, element }, doc.Nodes());
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:11,代码来源:SDMDocument.cs

示例9: CreateDocumentCopy

                /// <summary>
                /// Validate behavior of the XDocument copy/clone constructor.
                /// </summary>
                /// <returns>true if pass, false if fail</returns>
                //[Variation(Desc = "CreateDocumentCopy")]
                public void CreateDocumentCopy()
                {
                    try
                    {
                        new XDocument((XDocument)null);
                        Validate.ExpectedThrow(typeof(ArgumentNullException));
                    }
                    catch (Exception ex)
                    {
                        Validate.Catch(ex, typeof(ArgumentNullException));
                    }

                    XDeclaration declaration = new XDeclaration("1.0", "utf-8", "yes");
                    XComment comment = new XComment("This is a document");
                    XProcessingInstruction instruction = new XProcessingInstruction("doc-target", "doc-data");
                    XElement element = new XElement("RootElement");

                    XDocument doc = new XDocument(declaration, comment, instruction, element);

                    XDocument doc2 = new XDocument(doc);

                    IEnumerator e = doc2.Nodes().GetEnumerator();

                    // First node: declaration
                    Validate.IsEqual(doc.Declaration.ToString(), doc2.Declaration.ToString());

                    // Next node: comment
                    Validate.IsEqual(e.MoveNext(), true);
                    Validate.Type(e.Current, typeof(XComment));
                    Validate.IsNotReferenceEqual(e.Current, comment);
                    XComment comment2 = (XComment)e.Current;
                    Validate.IsEqual(comment2.Value, comment.Value);

                    // Next node: processing instruction
                    Validate.IsEqual(e.MoveNext(), true);
                    Validate.Type(e.Current, typeof(XProcessingInstruction));
                    Validate.IsNotReferenceEqual(e.Current, instruction);
                    XProcessingInstruction instruction2 = (XProcessingInstruction)e.Current;
                    Validate.String(instruction2.Target, instruction.Target);
                    Validate.String(instruction2.Data, instruction.Data);

                    // Next node: element.
                    Validate.IsEqual(e.MoveNext(), true);
                    Validate.Type(e.Current, typeof(XElement));
                    Validate.IsNotReferenceEqual(e.Current, element);
                    XElement element2 = (XElement)e.Current;
                    Validate.ElementName(element2, element.Name.ToString());
                    Validate.Count(element2.Nodes(), 0);

                    // Should be end.
                    Validate.IsEqual(e.MoveNext(), false);
                }
开发者ID:johnhhm,项目名称:corefx,代码行数:57,代码来源:SDMDocument.cs

示例10: CreateDocumentCopy

        public void CreateDocumentCopy()
        {
            Assert.Throws<ArgumentNullException>(() => new XDocument((XDocument)null));

            XDeclaration declaration = new XDeclaration("1.0", "utf-8", "yes");
            XComment comment = new XComment("This is a document");
            XProcessingInstruction instruction = new XProcessingInstruction("doc-target", "doc-data");
            XElement element = new XElement("RootElement");

            XDocument doc = new XDocument(declaration, comment, instruction, element);

            XDocument doc2 = new XDocument(doc);

            IEnumerator e = doc2.Nodes().GetEnumerator();

            // First node: declaration
            Assert.Equal(doc.Declaration.ToString(), doc2.Declaration.ToString());

            // Next node: comment
            Assert.True(e.MoveNext());
            Assert.IsType<XComment>(e.Current);
            Assert.NotSame(comment, e.Current);

            XComment comment2 = (XComment)e.Current;
            Assert.Equal(comment.Value, comment2.Value);

            // Next node: processing instruction
            Assert.True(e.MoveNext());
            Assert.IsType<XProcessingInstruction>(e.Current);
            Assert.NotSame(instruction, e.Current);

            XProcessingInstruction instruction2 = (XProcessingInstruction)e.Current;
            Assert.Equal(instruction.Target, instruction2.Target);
            Assert.Equal(instruction.Data, instruction2.Data);

            // Next node: element.
            Assert.True(e.MoveNext());
            Assert.IsType<XElement>(e.Current);
            Assert.NotSame(element, e.Current);

            XElement element2 = (XElement)e.Current;
            Assert.Equal(element.Name.ToString(), element2.Name.ToString());
            Assert.Empty(element2.Nodes());

            // Should be end.
            Assert.False(e.MoveNext());
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:47,代码来源:SDMDocument.cs

示例11: ExecuteXDocumentVariation

 public void ExecuteXDocumentVariation(XNode[] content, int index)
 {
     XDocument xDoc = new XDocument(content);
     XDocument xDocOriginal = new XDocument(xDoc);
     XNode toRemove = xDoc.Nodes().ElementAt(index);
     using (UndoManager undo = new UndoManager(xDoc))
     {
         undo.Group();
         using (EventsHelper docHelper = new EventsHelper(xDoc))
         {
             toRemove.Remove();
             docHelper.Verify(XObjectChange.Remove, toRemove);
         }
         undo.Undo();
         Assert.True(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
     }
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:17,代码来源:EventsRemove.cs

示例12: ParseXmlDoc

        private static IXmpMeta ParseXmlDoc(XDocument document, ParseOptions options)
        {
            object[] result = new object[3];

            result = FindRootNode(document.Nodes(), options.RequireXmpMeta, result);
            if (result != null && result[1] == XmpRdf)
            {
                var xmp = ParseRdf.Parse((XElement)result[0]);
                xmp.SetPacketHeader((string)result[2]);
                // Check if the XMP object shall be normalized
                if (!options.OmitNormalization)
                {
                    return XmpNormalizer.Process(xmp, options);
                }
                return xmp;
            }
            // no appropriate root node found, return empty metadata object
            return new XmpMeta();
        }
开发者ID:tehkyle,项目名称:xmp-core-dotnet,代码行数:19,代码来源:XmpMetaParser.cs

示例13: ExecuteXDocumentVariation

 public void ExecuteXDocumentVariation()
 {
     XNode[] content = Variation.Params[0] as XNode[];
     int index = (int)Variation.Params[1];
     XDocument xDoc = new XDocument(content);
     XDocument xDocOriginal = new XDocument(xDoc);
     XNode toRemove = xDoc.Nodes().ElementAt(index);
     using (UndoManager undo = new UndoManager(xDoc))
     {
         undo.Group();
         using (EventsHelper docHelper = new EventsHelper(xDoc))
         {
             toRemove.Remove();
             docHelper.Verify(XObjectChange.Remove, toRemove);
         }
         undo.Undo();
         TestLog.Compare(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
     }
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:19,代码来源:EventsRemove.cs

示例14: RunValidTests

 /// <summary>
 /// Runs test for valid cases
 /// </summary>
 /// <param name="nodeType">XElement/XAttribute</param>
 /// <param name="name">name to be tested</param>
 public void RunValidTests(string nodeType, string name)
 {
     XDocument xDocument = new XDocument();
     XElement element = null;
     try
     {
         switch (nodeType)
         {
             case "XElement":
                 element = new XElement(name, name);
                 xDocument.Add(element);
                 IEnumerable<XNode> nodeList = xDocument.Nodes();
                 TestLog.Compare(nodeList.Count(), 1, "Failed to create element { " + name + " }");
                 xDocument.RemoveNodes();
                 break;
             case "XAttribute":
                 element = new XElement(name, name);
                 XAttribute attribute = new XAttribute(name, name);
                 element.Add(attribute);
                 xDocument.Add(element);
                 XAttribute x = element.Attribute(name);
                 TestLog.Compare(x.Name.LocalName, name, "Failed to get the added attribute");
                 xDocument.RemoveNodes();
                 break;
             case "XName":
                 XName xName = XName.Get(name, name);
                 TestLog.Compare(xName.LocalName.Equals(name), "Invalid LocalName");
                 TestLog.Compare(xName.NamespaceName.Equals(name), "Invalid Namespace Name");
                 TestLog.Compare(xName.Namespace.NamespaceName.Equals(name), "Invalid Namespace Name");
                 break;
             default:
                 break;
         }
     }
     catch (Exception e)
     {
         TestLog.WriteLine(nodeType + "failed to create with a valid name { " + name + " }");
         throw new TestFailedException(e.ToString());
     }
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:45,代码来源:XLinqErrata4.cs

示例15: GetXSchema

		XElement GetXSchema(XDocument Model)
			{
			foreach (XElement XRoot in Model.Nodes().OfType<XElement>())
				{
				if (XRoot.Name.LocalName != "Edmx")
					continue;
				foreach (XElement XRuntime in XRoot.Nodes().OfType<XElement>())
					{
					if (XRuntime.Name.LocalName != "Runtime")
						continue;
					foreach (XElement XStorageModels in XRuntime.Nodes().OfType<XElement>())
						{
						if (XStorageModels.Name.LocalName != "StorageModels")
							continue;
						foreach (XElement XHelper in XStorageModels.Nodes().OfType<XElement>())
							{
							if (XHelper.Name.LocalName == "Schema")
								{
								return XHelper;
								}
							}
						}
					}
				}
			return null;
			}
开发者ID:heinzsack,项目名称:DEV,代码行数:26,代码来源:WCFStandards.svc.cs


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