linq-to-xml

Update elements using LINQ to XML?

≯℡__Kan透↙ 提交于 2019-12-23 04:26:26
问题 I have the following XML, but I am having a hard time figuring out how to update the elements directly using LINQ to XML: XElement settings = XElement.Parse ( @"<?xml version='1.0' encoding='utf-8'?> <soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:wsa='http://schemas.xmlsoap.org/ws/2004/08/addressing' xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis

LINQ to XML - Reading XML Document

混江龙づ霸主 提交于 2019-12-23 04:12:22
问题 Could someone please help me how to read the XML Document below using Linq to XML please? <?xml version='1.0' encoding='UTF-8' ?> <cXML> <Request> <OrderRequest> <OrderRequestHeader orderID="xy1234" orderDate="2007-01-1T15:5400+10:00" type="new" orderVersion="001"> <Total> <Money currency="NZ">34.06</Money> </Total> <ShipTo> <Address> <Name xml:lang="en">xyz</Name> <PostalAddress name="xyz"> <Street>xyz street</Street> <City>xyz</City> </PostalAddress> </Address> </ShipTo> <BillTo> <Address>

Compare 2 XML files using just C#

倾然丶 夕夏残阳落幕 提交于 2019-12-23 04:04:45
问题 I'm looking for a way to compare to XML files (examples below) and create a list containing the xpath to the differences in the two files so I can then check what has changed. can this be done in Linq or will I need to use MS Diff patch, I would really like to do it all in C# without any additional Dlls. Or should I just loop trough one XML file and compare it to the other, but then if I do this I may miss any new or deleted nodes! File A <info> <Retrieve> <LastNameInfo> <LNameNum>1</LNameNum

Restructure an XML tree based on sequence of elements with “ID” and “parent ID”

泪湿孤枕 提交于 2019-12-23 03:59:12
问题 What I want to happen is that I want to put inside the element whose ID is equal to ParentID? So like in my example the Group whose ParentId=1 should be inside the Group whose Id=1 How can I possibly do this? Got so confused.. As of now here is my code: XElement xroot = new XElement("Root"); XElement xnavigations = null; XElement xmenus = null; foreach (DataRow navigations in GetNavigationSets().Rows) { xnavigations = new XElement("Group", new XElement("GroupName", navigations["name"]

My code is very inefficient for this simple Linq usage

一曲冷凌霜 提交于 2019-12-23 01:27:09
问题 I have the following method that is supposed to parse information from an XML response and return a collection of users. I've opted into creating a Friend class and returning a List<Friend> to the calling method. Here's what I have so far, but I noticed that the ids.ToList().Count method parses every single id element to a List, then does it again in the for conditional. It's just super ineffective. public List<Friend> FindFriends() { List<Friend> friendList = new List<Friend>(); var friends

add parent to xml linq

那年仲夏 提交于 2019-12-23 01:11:56
问题 Is it possible to add parent to xml elements ? <node1> <node2></node2> <node2></node2> </node1> and I would like to have : <node1> <node3> <node2></node2> <node2></node2> </node3> </node1> so added node3 as parent for node 2 elements in this part 回答1: XElement lastparent = node2.Parent; node2.Remove(); node3.Add(node2); lastparent.Add(node3); EDIT In order to fit your edit: XElement node1 = yourDocument.Element("node1"); XElement[] nodes2 = node1.Elements("node2"); XElement node3 = new

Check if an element exists in XML

半世苍凉 提交于 2019-12-22 12:54:33
问题 XML: <CONFIGURATION> <Files> <File>D:\Test\TestFolder\TestFolder1\TestFile.txt</File> <File>D:\Test\TestFolder\TestFolder1\TestFile01.txt</File> <File>D:\Test\TestFolder\TestFolder1\TestFile02.txt</File> <File>D:\Test\TestFolder\TestFolder1\TestFile03.txt</File> <File>D:\Test\TestFolder\TestFolder1\TestFile04.txt</File> </Files> <SizeMB>3</SizeMB> <BackupLocation>D:\Log backups\File backups</BackupLocation> </CONFIGURATION> Code: private void btnLinq_Click(object sender, EventArgs e) {

Parsing XHTML with DTD using XDocument

邮差的信 提交于 2019-12-22 11:59:18
问题 I need to get plain text from XHTML documents. I am sure I already read somewhere here, that XDocument on WP7 does not support DTD. I cannot find it though. Well, when I try to parse XHTML with DTD using XDocument, it throws NotSuportedException. Last call in stacktrace is at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl() . That is exactly same even if I try to use some dummy XmlResolver - it doesn't really get called. (following answer in this question). So I assume that WP7 really doesn't

Parsing XHTML with DTD using XDocument

我怕爱的太早我们不能终老 提交于 2019-12-22 11:59:03
问题 I need to get plain text from XHTML documents. I am sure I already read somewhere here, that XDocument on WP7 does not support DTD. I cannot find it though. Well, when I try to parse XHTML with DTD using XDocument, it throws NotSuportedException. Last call in stacktrace is at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl() . That is exactly same even if I try to use some dummy XmlResolver - it doesn't really get called. (following answer in this question). So I assume that WP7 really doesn't

Parsing XHTML with DTD using XDocument

我与影子孤独终老i 提交于 2019-12-22 11:58:01
问题 I need to get plain text from XHTML documents. I am sure I already read somewhere here, that XDocument on WP7 does not support DTD. I cannot find it though. Well, when I try to parse XHTML with DTD using XDocument, it throws NotSuportedException. Last call in stacktrace is at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl() . That is exactly same even if I try to use some dummy XmlResolver - it doesn't really get called. (following answer in this question). So I assume that WP7 really doesn't