linq-to-xml

Xdocument, picking the right nodes

安稳与你 提交于 2019-12-11 09:27:39
问题 I'm trying to construct a linq query that pulls all nodes that have a particular element. In the case below, you'll notice that the second entry has a few extra elements: DisplayOnSignup, SortOrder, etc. I'd like the linq to give me all entry nodes that have a SortOrder element. The xml doc looks like this: <?xml version="1.0" encoding="UTF-8"?> <feed > <entry> <link href="/ws/customers/testacct/lists/removed" rel="edit"></link> <id>http://api.constantcontact.com/ws/customers/testacct/lists

Parsing XML file with nodes of same name with VB.NET

自古美人都是妖i 提交于 2019-12-11 09:25:46
问题 Once again having issues parsing XML. I've got almost all of it figured out but am stuck where I have multiple nodes with the same name. Here's a snippet from the XML <HotelDetailsRsp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" TraceId="0.7055475" TransactionId="72CEA41F0A0758AA26AA4A14D780FC06" ResponseTime="1069"> <RequestedHotelDetails xmlns="http://www.travelport.com/schema/hotel_v19_0"> <HotelProperty HotelChain="LC" HotelCode="14645

Reading complex xml in C#

爷,独闯天下 提交于 2019-12-11 08:51:54
问题 i am trying to read an xml file, the format of the file as follow: <rootnode> <a>first<b>1st</b></a> <a>second<b>2nd</b></a> </rootnode> i tried to use XDocument like this: XDocument loadedData = XDocument.Load("file.xml"); var data = from query in loadedData.Descendants("a") select new myClass { Word = (string)query.Value, secondWord = (string) query.Element("b") }; but it didnt work, as the (string)query.Value will bring me the whole line;"first 1st " is there any way to get the text

LINQ to XML query returning wrong data

笑着哭i 提交于 2019-12-11 08:35:49
问题 I have this xml <?xml version="1.0" encoding="utf-8" ?> <Departments> <Department> <id>001</id> <Section> <SectionId>001001</SectionId> <Room> <RoomID>001001001</RoomID> <Owner>guest1</Owner> </Room> <Room> <RoomID>001001002</RoomID> <Owner>guest11</Owner> </Room> </Section> <Section> <SectionId>001002</SectionId> <Room> <RoomID>001002001</RoomID> <Owner>guest2</Owner> </Room> </Section> </Department> </Departments> and this is my code using Linq to Xml var xDoc = XDocument.Load(inputUrl);

Is this the most efficient way of loading xml values into a structure?

跟風遠走 提交于 2019-12-11 08:35:10
问题 I am trying to load data from XML string into a structure of some sort so once loaded I can then say Data.PropertyName to read the values. Is the below code the most optimal way of loading the data into the structure? Obviously calling First() has a memory hit so if you have elements with sub elements will calling First() for each one become an issue? Thanks string xml = @"<ROOT> <ID>1</ID> <NAME>RF1</NAME> <STAT>10200</STAT> <TEST> <ID>1</ID> <NAME>BIGUN</NAME> </TEST> </ROOT> "; XElement

DataTable to Xdocument Custom

a 夏天 提交于 2019-12-11 08:34:55
问题 i have a datatable that looks like the following type cname ctable text allowgroupping StringFilter AAA Table1 Good,Bad Yes StringFilter BBB Table2 Ugly No StringFilter CCC Table3 Lucky Yes and from that table i want to produce the following XML <Filters Date ="25.07.2012 22:50"> <StringFilter cname="AAA" ctable="Table1" allowgroupping="Yes">Good,Bad</StringFilter> <StringFilter cname="BBB" ctable="Table2" allowgroupping="No">Ugly</StringFilter > <StringFilter cname="CCC" ctable="Table3"

NullReferenceException with XML Document

谁说我不能喝 提交于 2019-12-11 08:34:25
问题 When this line of code is run, I receive a System.NullReferenceException. // Occurs on this line if (xDoc.Root.Element("data").Element("forecast").Element("record").Value == "0") { tempnow.Text = xDoc.Root.Element("data").Element("forecast").Element("pop").Value; } Xdoc is defined below the class, if this is related to it. { public partial class MainPage : PhoneApplicationPage { XDocument xDoc; This is the XML document I am attempting to access and find the value of "record". This is also the

Why isn't it possible to combine LINQ to XML with LINQ to SQL?

落花浮王杯 提交于 2019-12-11 08:28:12
问题 I have this piece of code: var xml = XDocument.Load(filePath); var taxReturns = (from t in xml.Descendants("aangiftes").Elements() where t.Name == "ib" select new Domain.TaxReturn { FiscalNumber = t.Attribute("sofinr").Value, Guid = Guid.Parse(t.Attribute("guid").Value), LastFormOpen = t.Attribute("lastformview").Value, Name = string.Empty, TaxYear = t.GetAttributeValue<short>("belastingjaar"), TaxForm = unitOfWork.TaxForms.FirstOrDefault(tf => tf.Code == t.Attribute("biljetsoort").Value), })

Recursively remove xml nodes using Linq to XML

混江龙づ霸主 提交于 2019-12-11 07:29:46
问题 Fairly new to Linq to XML How does one remove xml node ( recursively using relation ) and save the document. Structure of the xml cannot be altered as it comes from service.Below is the xml from a tasks service. Every task can have nested tasks for which there might be one or more nested tasks. Nesting is intended to be upto N level . When one of parent tasks are removed using linq to xml how do i remove all of it's children? How do i know all the nodes where successfully removed? Xml: <Tasks

Null reference exception in my LINQ to XML code

霸气de小男生 提交于 2019-12-11 07:29:30
问题 I have been playing around with linking XML files to dropdown lists and gridviews. I have managed to populate one dropdown list from the XML document and then a gridview to another but when try to add a where clause, I get a null reference exception and not sure why. How can I resolve this? XDocument xmlDoc = XDocument.Load(Server.MapPath("XMLFile.xml")); var q = from c in xmlDoc.Descendants("Images") where c.Attribute("PropertyId").Value == DropDownList1.SelectedValue.ToString() select new {