linq-to-xml

How do I remove the CDATA tag of an XElement?

谁说我不能喝 提交于 2020-01-14 03:32:08
问题 I have some code that receives some XML and there is the possibility that a CDATA tag element will be present. A flag is passed into the method that states whether the CDATA tag should be present, if the flag is false, then the CDATA tag should be removed if present, how would I do this without parsing the query.Value? private static void CDataTagUtility(XmlDocument catalog, XElement newData, bool addCdataTag) { XElement query = newData.Element("Query").Element("CommandText"); if (addCdataTag

How to query with the datetime value using LINQ to XML?

时光毁灭记忆、已成空白 提交于 2020-01-14 03:18:07
问题 I am developing window phone 7 application in silverlight. I am new to the silverlight. I am also new to LINQ to XML. In my application the user select the date & submit some transaction details into the application. The details gets stored in XML File. I am using the custom date control in my application for the date selection as follows private void DatePicker_ValueChanged(object sender, DateTimeValueChangedEventArgs e) { AppObj = Application.Current as App; AppObj.date = (DateTime

Linq to Xml to Datagridview

狂风中的少年 提交于 2020-01-13 18:57:38
问题 Right, starting to go crazy here. I have the following code: var query = (from c in db.Descendants("Customer") select c.Elements()); dgvEditCusts.DataSource = query.ToList(); In this, db relates to an XDocument.Load call. How can I get the data into the DataGridView? Just thought I should mention: it returns a completely blank dgv. Not that the XML should matter too much, but here's an example: <Root> <Customer> <CustomerNumber>1</CustomerNumber> <EntryDate>2010-04-13T21:59:46.4642+01:00<

Using XNamespace to create nicely formatted XML

☆樱花仙子☆ 提交于 2020-01-13 10:53:08
问题 I want to create a Xml file that looks something like this: <Root xmlns:ns1="name1" xmlns:ns2="name2"> <ns1:element1 /> <ns1:element2 /> <ns2:element3 /> </Root> How can I accomplish this using XAttribute, XElement, XNamespace, and XDocument where the namespaces are dynamically added. 回答1: I assume by "namespaces are dynamically added" you mean the namespace prefix. This generates the document, how close is it to what you meant? XNamespace ns1 = "name1", ns2 = "name2"; XElement elem = new

Using XNamespace to create nicely formatted XML

早过忘川 提交于 2020-01-13 10:53:07
问题 I want to create a Xml file that looks something like this: <Root xmlns:ns1="name1" xmlns:ns2="name2"> <ns1:element1 /> <ns1:element2 /> <ns2:element3 /> </Root> How can I accomplish this using XAttribute, XElement, XNamespace, and XDocument where the namespaces are dynamically added. 回答1: I assume by "namespaces are dynamically added" you mean the namespace prefix. This generates the document, how close is it to what you meant? XNamespace ns1 = "name1", ns2 = "name2"; XElement elem = new

LINQ to XML: What is the most effective way to move nodes up and down

萝らか妹 提交于 2020-01-13 09:48:18
问题 I need to move sibling nodes before and after certain nodes. Here is the code im working with <tabs> <tab> <name>Overview</name> </tab> <tab> <name>Testing</name> </tab> <tab> <name>Performance</name> </tab> <tab> <name>Braking</name> </tab> </tabs> I would like to move the tab with testing in it above Overview. How would I go about this using linq to XML? 回答1: Sorry, this is VB.NET and XML Literals, but it can be done old school in C#. The idea here is to use the Reverse extention method:

XDocument.Load(XmlReader) Possible Exceptions

◇◆丶佛笑我妖孽 提交于 2020-01-13 07:31:26
问题 What are the possible exceptions that can be thrown when XDocument.Load(XmlReader) is called? It is hard to follow best practices (i.e. avoiding generic try catch blocks) when the documentation fails to provide crucial information. Thanks in advance for your assistance. 回答1: MSDN says: The loading functionality of LINQ to XML is built upon XmlReader.Therefore, you might catch any exceptions that are thrown by the XmlReader. Create overload methods and the XmlReader methods that read and parse

Can I assign a BaseUri to an XDocument?

眉间皱痕 提交于 2020-01-13 02:13:23
问题 When I load an XML document from disk into an XDocument, that XDocument has a ready-only property BaseUri that contains the original XML document's location on disk. In other words, XDocument doc = XDocument.Load(@"c:\temp\doc.xml"); Console.Out.WriteLine(doc.BaseUri); // Outputs "file:///c:/temp/doc.xml" If I create a new XDocument from scratch, it has no BaseUri. For example: XDocument doc = new XDocument(new XElement("test")); Console.Out.WriteLine(doc.BaseUri); // Outputs nothing Can I

Is there an XPath equivilent for Linq to XML?

杀马特。学长 韩版系。学妹 提交于 2020-01-11 20:01:14
问题 I have been using Linq to XML for a few hours and while it seems lovely and powerful when it comes to loops and complex selections, it doesn't seem so good for situations where I just want to select a single node value which XPath seems to be good at. I may be missing something obvious here but is there a way to use XPath and Linq to XML together without having to parse the document twice? 回答1: You can still use XPath, with the XPathEvaluate, XPathSelectElement and XPathSelectElements

LINQ to XML getting XElement values

旧城冷巷雨未停 提交于 2020-01-11 14:30:08
问题 I am having an issue with getting some values back from LINQ to XML query. I have got the XML from a SOAP web service and passed this through and parsed this into an XDocument to query The XML: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <GetCollectionByUprnAndDateResponse xmlns=\"http://webservices.whitespacews.com/\"