xdocument

XDocument parsing value

In the code snippet below, I only have 1 element in the XML that has text data: <element>like this</element> All the other elements have attributes or nothing. Why would my parsing below seem to indicate that ALL of my elements have "like this" as text data? thx StreamWriter sw = new StreamWriter(out_file_name_); var xd = XDocumen...

XDocument memory usage problem

Hi, I have a small application that builds up a xml document using XDocument. However, after a while the app is using more than 1gb ram. So I was wondering if there is anyway to make XDocument use the disk instead of in-memory. For example by opening a StreamWriter and save it to a file on the go. Thank you in advance. ...

How to iterate through an XDocument, getting complete XML structure, object by object?

Hi I have an XmlDocument which I can traverse with XmlNode or convert it to a XDocument and traverse it via LINQ. <Dataset> <Person> <PayrollNumber>1234567</PayrollNumber> <Surname>Smith-Rodrigez</Surname> <Name>John-Jaime-Winston Junior</Name> <Skills> <Skill>ICP</Skill> <Ski...

How do I have to change this XML string so that XDocument.Parse reads it in?

In the following code, I serialize an object into an XML string. But when I try to read this XML string into an XDocument with XDocument.Parse, it gives me this error: Invalid data at root level. The XML is: <?xml version="1.0" encoding="utf-8"?> <Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://ww...

replacing xml tag with html value

Hi! I'm working with c# .Net I have a question, I'm loading Xml file with XDocument.xDoc.Load(file), but it fails because in my content I also have xml tags: Example: <root><abc><deg></abc></root> My problem is that the Load function treats the <deg> as an Xml tag without a matching "</deg>"... My question is, how can i replace th...

Using XDocument to write raw XML

I'm trying to create a spreadsheet in XML Spreadsheet 2003 format (so Excel can read it). I'm writing out the document using the XDocument class, and I need to get a newline in the body of one of the <Cell> tags. Excel, when it reads and writes, requires the files to have the literal string &#10; embedded in the string to correctly sho...

creating xdocument structure

I am trying to index a drive to a xml file. My pitiful attempt is this: internal static void createIndex(String path, String driveLabel) { XDocument w = new XDocument(); w.Add(createStructure(path, new XElement("root"))); w.Save(driveLabel +".xml"); } internal static...

Add new XElement to an existing XElement if it doesn't already exist

How do I check to see if an element exists within a given element before trying to add it? Background: I have an XDocument X that contains as a child element Flowers which subsequently contains a series of elements that are each named Flower. Each Flower already has 2 child elements and I would like to add a 3rd element called Price. ...

How can i sort an XDocument by attribute

I have a Xml <Users> <User Name="Z"/> <User Name="D"/> <User Name="A"/> </User> I want to sort that by Name. I load that xml using XDocument. How can i view that xml sorted by Name. ...

XElement Add function adds xmlns="" to the XElement

I have a function which generates xml for a list object: public XDocument ToXML() { foreach (var row in this) { var xml = row.ToXml(); template.Root.Add(xml); } return template; } The template.ToString() reads: <RootElement xmlns="urn:testTools"> The xml reads: <Example><SubElement>testData</SubElement...

parsing xml with xDocument and xPath

<REETA xmlns="http://pria.org"&gt; - <AFFIDAVIT> <COUNTY_NAME>BOBBIES COUNTY</COUNTY_NAME> <DOC_TYPE>DEED</DOC_TYPE> <DOC_DATE>2010-02-19T05:14:58</DOC_DATE> <GROSS_SELL_PRICE>200000.00</GROSS_SELL_PRICE> <TAXABLE_SELL_PRICE>200000.00</TAXABLE_SELL_PRICE> <EXCISE_TAX_STATE>2560.00</EXCISE_TAX_STATE> <EXCISE_TAX_L...

reading value of node that has a specific attribute with Xdocument

Im trying to write a List of 'Documents' from an XML string, but i was wondering what is the best way to get the value of a node of certain attribute. More specifically in the sample I would like to set the value of aDocument.Source to the text "The Source" of the "field" node that has the "Source" value for the "name" attribute. Sampl...

Under High load XDocument.Parse Creating errors

Hi everyone, I am trying to access this webservice, The problem is that sometimes XDocument.Parse is not able to process and generates an error System.Xml.XmlException: Root element is missing. on the line: XDocument xmlDoc = XDocument.Parse(xmlData); Even though the XML sent is correct according to my logs. I was wondering, Is it p...

Validate a XDocument against schema without the ValidationEventHandler (for use in a HTTP handler)

Hi everyone, (I am new to Schema validation) Regarding the following method, System.Xml.Schema.Extensions.Validate( ByVal source As System.Xml.Linq.XDocument, ByVal schemas As System.Xml.Schema.XmlSchemaSet, ByVal validationEventHandler As System.Xml.Schema.ValidationEventHandler, ByVal addSchemaInfo As Boolean) I a...

Preserve carriage return when using XDocument.Parse

I have an application that is sensitive to a carriage return being \r\n or \n. I'm passing around a value in XML and when I parse it using XDocument the carriage retrun value is being converted to \n and I'm trying to find a way to keep it preserved as \r\n. string myVal = "1234\r\nabcd"; string xmlText = "<doc>" + myVal + "</doc>"; XDo...

Stop XDocument url encoding strings

I am trying to create an XML file to conform to someones XSD this XSD allows for XHTML content within its description tag. I have cut short the method hierarchy but basically it does the following: using System.Xml.Linq; public static XDocument Create() { XDocument doc = new XDocument( new XDeclaration...

get all the elements that have a particular element name

My xml looks like this: <nodes><skus><sku>abc</sku><sku>def123</sku></skus></nodes> I want to get all the elements with the name 'sku' I have a XDocument already loaded with the xml. List<XElement> elements = doc.Elements.Where( ??? ) or would I just do: doc.Elements("sku") ? I don't want this to return an error if there are n...

Determining if an XDocument File Exists

Hello Everyone, I am using LINQ and I was wondering what is the best way to create an XDocument and then check to make sure that the XDocument actually exists, much like File.Exists? String fileLoc = "path/to/file"; XDocument doc = new XDocument(fileLoc); //Now I want to check to see if this file exists Is there a way to do this? Th...

return xdocument from wcf service

How can i return xdocument from wcf service??? what i need to do to let wxf service's method return a object of xdocument? ...

Loading xml into a xdoc, and then initializing an object

My object looks like: public class Template { public string Title {get;set;} public string Body {get;set;} } xml that is stored in /files/test.xml in a web application (at the root): <nodes> <template name="someKey"> <node name="title">soem title</node> <node name="body">some body text here</node> </template> </nodes> ...