xdocument

How to load XML with special characters using XDocument.Load

**This is for silverlight application. I have a stream with xml data, which after loading massage the data and generate final file. I start by load using XDocument.Load(stream). One of the file was failing to load and after some research I foung out that one of the element has a value of 'First & Second' and load fails on hitting &. I...

How can I handle an empty namespace with XDocument.XPathEvaluate?

I'm trying to use XDocument and XPathEvaluate to get values from the woot.com feed. I'm handling other namespaces fine, but this example is giving me problems. <rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0"> <channel> <category text="Comedy" xmlns="http://www.itunes.com/dtds/podcast-1.0.dtd"&gt; </cate...

In-memory XML manipulation

I'm trying to do a find and replace in an OpenXML word document which I've openened into a MemoryStream. using (WordprocessingDocument _document = WordprocessingDocument.Open(_ms, true)) { var placeHolder = _document.MainDocumentPart.Document .Descendants<DocumentFormat.OpenXml.Wordprocessing.Text>() ...

How to search for .xml files within project files in Silverlight

I want to search for files with .xml extension within my silverlight project, for example (ApplicationRoot)/Resources/102.xml I know how to do this using System.IO.Directory: // create a collection to hold the file enumeration List<string> directoriesInFolder = new List<string>(); // using the file api to enume...

xml element not indented properly

i have created a xml file using c# but the main problem is that it is not indented i have used xmldocument.preserverwhitespace=true; ...

StyleCop happy creation of Xml using XDocument / XElement / XAttribute

I like to create xml using the following formatting: XDocument xml = new XDocument( new XElement("Root", new XElement("A", new XAttribute("X", xValue), new XAttribute("Y", yValue)), new XElement("B", new XAttribute("Z", zValue)), new XElement("C"))); It seems easy to read and kinda flows...

Merging xml documents using linq to xml and xdocument

I have the following xml: <DOCUMENT> <ARTICLE> <META name="bbb" value="7086" score="0.58" key="6007"/> <META name="ccc" value="7089" score="0.58" key="6008"/> <META name="ddd" value="7087" score="0.58" key="6009"/> </ARTICLE> </DOCUMENT> I need to use linq to xml and an xdocument to allow users in an asp.net page to edit ...

How can I check if an XDocument has at least one child?

I'm trying to check if a user exists from an XML response. When a user doesn't exist the response is like this: <ipb></ipb> What would be the best way for me to (in code) verify that a user doesn't exist? I was thinking of checking if it didn't have any child elements but I'm somewhat confused. Thanks for the help! public v...

How can I select an XML element if there are three of the same elements there?

Given this XML found here. How can I get each contact item individually? For example, say I wanted to get only twitter: I tried this: return doc.XPathSelectElement("/ipb/profile/contactinformation/contact[type/text() = 'LinkedIn']/value").Value; But that returns nothing. Any help? ...

How can I get an XML attribute?

Given this XML, how can I retrive the HEX color? <group> <span style="color:#DF0000; font-style: italic; font-weight: bold">Webmaster</span> </group> I need to retrieve everything inside of the style. Then I can use the String.Substring method with .IndexOf() to retrieve the color for my use. Thank you for the help. Incase anyon...

How can I grab all the child elements in XML?

From this XML response: http://www.dreamincode.net/forums/xml.php?showuser=335389 I want to grab all of the users friends. I need to grab all of the information from the friends. Usually with the help I've been given I would use the unique ID to grab each, but since each users doesn't have the same friends it has to be dynamic and I can...

My code is very inneficient, mind taking a look for this simple Linq usage?

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 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 a...

Why are all of my line-breaks changing from "/r/n" to "/n/" and how can I stop with from happening?

I am saving my files as xml documents, using XDocument.Save(path), and after saving and loading a document all of the line breaks have changed from "/r/n" to "/n/". Why is this happening and how can I fix it? ...

XDocument.Save creating 3 bad characters in XML

Hi when I do this: using (XmlWriter xw = new XmlTextWriter(fcService.SetCIRIFilePath(), Encoding.UTF8)) { debts.Save(xw); xw.Flush(); } My debts object is a XDocument object which I populated using LINQ to XML. However when I save it, it looks fine in notepad, but when opened with a binary/hex e...

How can I force XDocument to output "UTF-8" in the declaration line?

The following code produces this output: <?xml version="1.0" encoding="utf-16" standalone="yes"?> <customers> <customer> <firstName>Jim</firstName> <lastName>Smith</lastName> </customer> </customers> How can I get it to produce encoding="utf-8" instead of encoding="utf-16"? using System; using System.Collections.Generic; ...

How can I iterate through a collection with Foreach to build an XDocument?

The following code gives me the error: The best overloaded method match for 'System.Xml.Linq.XElement.XElement(System.Xml.Linq.XName, object)' has some invalid arguments. What do I have to change so I can iterate through my List<Customer> collection with Foreach building the XDocument? using System; using System.Collections.Ge...

For an XDocument descendants operation how can only return immediate child nodes?

For an XDocument descendants operation how can only return immediate child nodes? I have an operation along the lines of: XDocument xmlDc = XDocument.Load(dependencyFilePath); IEnumerable<IGrouping<string, XElement>> scriptNodes = from s in xmlDc.Descendants("script") select s; The problem is my XML doc is structured as follows ...

Linq to XML setting XElements from arrayList?

I am trying to set XElements with an ArrayList and having a bit of trouble. I basically want to be able to do a foreach loop, but not sure where I need to insert it. ArrayList cities = new ArrayList(); foreach (ListItem item in lstCities.Items) { cities.Add(item.Text); } new XElement("Cities", cities //not sure what to do here ...

How can I convert a byte[] response to a valid XDocument?

<?xml version="1.0" encoding="utf-8"?> <rsp stat="ok"> <image_hash>cxmHM</image_hash> <delete_hash>NNy6VNpiAA</delete_hash> <original_image>http://imgur.com/cxmHM.png&lt;/original_image&gt; <large_thumbnail>http://imgur.com/cxmHMl.png&lt;/large_thumbnail&gt; <small_thumbnail>http://imgur.com/cxmHMl...

Selecting a XElement from a XDocument

Hey all I really didn't want to ask for help as I know I'll eventually figure it out, but I've spent too much time, if the document had parent tags or a better structure, it would be a piece of cake. Sadly I'm downloading the document, and I just can't figure out how to get the data. I've tried a a few linq queries and a foreach using ...