linq to xml There are multiple root elements.

When adding XML nodes

var temp2 = temp1.Element("staticContent");
            if (temp2 != null)
            {
                string str = "<remove fileExtension=\".svg\" />\r\n               <mimeMap fileExtension=\".svg\" mimeType=\"image/svg+xml\" />\r\n               <remove fileExtension=\".nupkg\" />\r\n               <mimeMap fileExtension=\".nupkg\" mimeType=\"application/zip, application/octet-stream\" />\r\n               <remove fileExtension=\".webm\" />\r\n               <mimeMap fileExtension=\".webm\" mimeType=\"video/webm\" />\r\n               <remove fileExtension=\".mp4\" />\r\n               <mimeMap fileExtension=\".mp4\" mimeType=\"video/mp4\" />";
                temp2.AddFirst(XElement.Parse(str));
            }

Multiple nodes must be separated from, and added one by one

When parsing XML strings

    [Test]
        public void XmlTest()
        {
            string xml = "<Record ID=\"135\" Key=\"CustomTableItemID\" /> <Record ID=\"23\" Key=\"CustomTableID\" />";
            XElement element = XElement.Parse(xml);
            Console.WriteLine(element);
        }

You need to add a root node for parsing

Similar Posts: