linq-to-xml

Why the same LINQ expression behaves differently in two different foreach loops?

 ̄綄美尐妖づ 提交于 2019-12-13 07:05:47
问题 I have following XML. <Parts> <Part name="Part1" disabled="true"></Part> <Part name="Part2" disabled="false"></Part> <Part name="Part3" ></Part> <Part name="Part4" disabled="true"></Part> </Parts> I want to remove the nodes for which disabled attribute is set to true . If 'disabled' attribute is not used for any 'Part' element, it means it's not disabled. I wrote following code: XmlNode root = xmlDoc.DocumentElement; List<XmlNode> disabledNodes = new List<XmlNode>(); foreach(XmlNode node in

Web service return only XML

点点圈 提交于 2019-12-13 06:07:02
问题 I am consuming a web services using Service Reference. I converted the result return using ToString(). using (ConnectClient client = new ConnectClient("ESConnect")) { result = client.actiService("ssss", "sss", "sss").ToString(); The I use xml.linq to read the xml. using (XmlReader reader = XmlReader.Create(new StringReader(result))) I get the following error: The content type text/plain of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using

Merging XML Elements with LINQ

心已入冬 提交于 2019-12-13 05:40:18
问题 I have two XML documents. My objective is to replace one of the nodes in the first document with the entire contents of the second Xml documents. So the first document - Parent looks something like this: <Root> <AgencyName = "Some Agency"/> <Originator = "Some other Agency"/> <Type = "AnonymousType"/> <Details/> </Root> The second document - children looks like this: <Root> <Details> <Detail1> ... </Detail1> <Detail2> ... </Detail2> <Detail3> ... </Detail3> </Details> </Root> The node

Linq to XML: XML query (.Net Windows Form app)

时光总嘲笑我的痴心妄想 提交于 2019-12-13 04:23:18
问题 I'm trying to build a query that returns a collection that contains a customer's information based upon the selection of a customer ID. When the user selects a customer from the combobox (cboCustomer), the selected index changed event kicks off and that method below contains the query. Unfortunately the query is not working. When I hover over the result in custRecord* strong text *, I receive the error, "Object reference not set to an instance of an object." Thanks in advance from a newbie to

How to load an XML file from a file in the solution, build with Embedded Resource?

ⅰ亾dé卋堺 提交于 2019-12-13 03:39:45
问题 Here's an outline of my solution: I've set the build to Embedded Resource and when I generate the application the XML file doesn't appear in the /Release folder. This is correct, I want this behavior. Now I'm trying to load that file into an XDocument so I can parse the data within: class Program { static void Main(string[] args) { Console.WriteLine("Parsing XML."); XDocument championXml = XDocument.Load("Champions.xml"); Console.ReadKey(); } } And I get a file not found error because it's

C# Returned .XML to class

孤者浪人 提交于 2019-12-13 02:18:57
问题 I am tring to give an information from friendfeed API. As you see in code, I am using an HttpRequest to get information. It's ok. After that I am reading XML just fine with LINQ. But now I create a "feed" class and I want to create an object for every returned value (i from finaltoclass). How can I do this? Can you help me with this? Thank you. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO; using System.Xml; using

Linq to XML Question

家住魔仙堡 提交于 2019-12-12 23:51:14
问题 Given the following XML, what query can I use to extract the value of preapprovalKey to a string variable? Still a little new to LINQ to XML. <?xml version="1.0" encoding="UTF-8" ?> - <ns2:PreapprovalResponse xmlns:ns2="http://svcs.paypal.com/types/ap"> - <responseEnvelope> <timestamp>2011-04-05T18:35:32.952-07:00</timestamp> <ack>Success</ack> <correlationId>7cec030fa3eb2</correlationId> <build>1655692</build> </responseEnvelope> <preapprovalKey>PA-9AG427954Y7578617</preapprovalKey> </ns2

Check for Existence of a Result in Linq-to-xml

只愿长相守 提交于 2019-12-12 19:17:25
问题 I'm using Linq-to-XML to do a simple "is this user registered" check (no security here, just making a list of registered users for a desktop app). How do I handle the result from a query like this: var people = from person in currentDoc.Descendants("Users") where (string)person.Element("User") == searchBox.Text select person; I understand the most common way to use the result would be something like foreach (var line in people){ //do something here } but what do you do if person comes back

Is there a faster way to check for an XML Element in LINQ to XML, and parse a bool?

China☆狼群 提交于 2019-12-12 19:16:19
问题 FYI, This is very similar to my last question: Is there a faster way to check for an XML Element in LINQ to XML? Currently I'm using the following extension method that I made to retrieve the bool values of elements using LINQ to XML. It uses Any() to see if there are any elements with the given name, and if there are, it parses the value for a bool. Otherwise, it returns false. The main use for this method is for when I'm parsing XML into C# objects, so I don't want anything blowing up when

Dealing with XElement null value

大城市里の小女人 提交于 2019-12-12 18:30:52
问题 I have an xml that I am querying. One of the nodes is missing. So when I call XElement.Value I get a null exception. What is the best way to guard against this? I know I can write an extension method, but I am wondering is there something build into the language for this? 回答1: use the null coalesce operator ?? Given an XElement elem: var value = (string)elem ?? "empty"; 来源: https://stackoverflow.com/questions/2057281/dealing-with-xelement-null-value