xdocument

Sorting all the elements in a XDocument

Hi, I have a XDocument where I'd like to sort all of the elements alphabetically. Here's a simplified version of the structure: <Config> <Server> <Id>svr1</Id> <Routing> <RoutingNodeName>route1</RoutingNodeName> <Subscription> <Id>1</Id> </Subscription> <RoutingParameters id="Routing...

Can't use an XDocument in Silverlight?

I'm creating a Windows Phone 7 application that will consume an exposed webservice. For now, I want to load a dummy xml file and parse information from that. I'm used to using XDocument for things like this, but it seems I can't type in the using namespace in my code. Any other ideas? ...

Will this XML parsing work?

public Envio(int id) { XDocument xml = XDocument.Parse(LoadFromService(id)); ID = xml.Element("envio") .Element("de").Value; De = xml.Element("envio") .Element("de").Value; Para = xml.Element("envio") .Element("para").Value; Fecha = xml.Element("envio") .Element("fech...

.NET MVC Linq -> XML RSS reader : Twitter XML Parsing Error

It seems like no matter what I do, I cannt get my twitter RSS feed to show up on my view. I'm not getting any errors, and the RSS feed loads correctly, I just can't grab the Model's information... Here's my ViewModel namespace MvcMusicStore.ViewModels { public class HomeRssFeedViewModel { public IEnumerable<TwitterPosts...

How to load an XML file that's located on my desktop?

For testing purposes I'd like to load an XML file to an XDocument object. How can I accomplish this? Thanks! ...

Prevent XmlTextReader from expanding entities

I am trying to read a XML document without expanding the entities, do some manipulations to it, and re-save it with the unexpanded entities as they were initially. When using the XDocument directly, it fails to load, throwing an exception tell me it has unexpanded entities: XDocument doc = XDocument.Load(file); // <--- Exception // .....

Linq to Sql method return type

I have a stored procedure that has FOR XML AUTO and I use it in a dbml file. The problem is that I want the return type to be XDocument. For now it returns the xml string cut into pieces. I can use someting like : foreach(spMyProcedure_GetResult getResult in list) { sb.Append(getResult.XML_F52E2B61_18A1_11d1_B105_00805F49916B); }...

Is there a way to create an immutable (read-only) XDocument?

I have an API that returns XElement-s, and I want the document behind those XElement-s to be immutable (read-only). I need it for: 1) Not to give devs an ability to change it accidentally :) 2) Improving performance - creating a copy of an XDocument might be a performance "heavy" operation in some cases. It doesn't seem to possible to ...

Validating an XDocument instance against its own schema reference.

I'm using the XDocument.Validate extension method to validate my instance. Is there anyway to hold an XML instance accountable to its own schema reference? This seems like something that would be fairly implicit. Unfortunately simply loading the instance into an XDocument doesn't seem to perform this validation implicitly. ...

Add Stylesheet reference to XML Document in Linq?

I create an XML Doc and wanted have a reference to the XSLT file. //<?xml-stylesheet type="text/xsl" href="OBReport.xslt"?> to this XML generation: XElement xml = new XElement("ReportedOn", from dl in EL.DocumentLog.ToList() join o in EL.Organization on dl.OrganizationID eq...

Wierdness with XDocument, XPath and namespaces

I have an XML document that looks like this: <kmsg xmlns="http://url1" xmlns:env="url1" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xsi:schemaLocation="http://location that does not exist.xsd"> <header> <env:envelope> <env:source branch="907" machine="0" password="J123"/> </env:envelope> </header> <body> <Or...

building an XDocument with a webclient downloaded string

I am using the following methods to download an xml file private void LoadXMLFile() { WebClient xmlClient = new WebClient(); xmlClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(XMLFileLoaded); xmlClient.DownloadStringAsync(new Uri("chart.xml", UriKind.RelativeOrAbsolute)); } void XMLFileLoaded(object sen...

DataSet to XDocument Conversion and back

I am working on an application where I need to convert a DataSet into XDOcument in the Middle Tier ( XDOcument is much lighter to transport than XmlDocument) and then covert the XDocument back into DataSet at the Front end. I am not able to figure out an efficient way of doing this. As of now I am converting the DataSet to XMlDocumenmt ...

Trying to Filter XML using XPath

I'm trying to filter an XML file using XPath. The XPath that I'm using is definitely filtering to the data that I want, but I'm just not sure how to filter the file overall. Here's the sample XML file: <fields> <field name='F'> <field name='0'><value>F.0 stuff</value></field> <field name='1'><value>F.1 stuff</val...

Different behaviors between XmlDocument.LoadXml and XDocument.Parse

Our project has been converted to use XDocument from XmlDocument few days ago, but we found a strange behavior while processing XML entity in attribute value with XDocument.Parse, the sample code as following: The XML string: string xml = @"<char symbol=""&#x0;"">"; The XmlDocument.LoadXml code and result: XmlDocument xmlDocument...

XPath expression to select nodes between a defined sequence of preceding and succeeding nodes

I've got the following structured XML file: <w:document> <w:body> <w:p> <w:r> <w:t/> </w:r> </w:p> <w:p> <w:r> <w:t/> </w:r> </w:p> <w:p> <w:r> <w:instrText/> </w:r> </w:p> ...

Force XDocument to write to String with UTF-8 encoding

I want to be able to write XML to a String with the declaration and with UTF-8 encoding. This seems mighty tricky to accomplish. I have read around a bit and tried some of the popular answers for this but the they all have issues. My current code correctly outputs as UTF-8 but does not maintain the original formatting of the XDocument...

i'm trying to work with xml linq xdocument in vb.net

I'm trying to write a windows phone 7 app which reads from an xml using xdocument but i'm having a few problems. If I do this: Dim xml As XDocument = XDocument.Load(e.Result) System.Diagnostics.Debug.WriteLine(xml.ToString) Or this: System.Diagnostics.Debug.WriteLine(xml.Elements.Value.ToString) then the xml data is output to the ...

How to extracting the XML contents of an XDocument variable ?

I have the a full XML file in an XDocument variable which I get from some API like this using (var reader = XmlReader.Create("website")) { doc = XDocument.Load(reader); } I need to get the structure of the XML and navigate through its nodes, but through the XDocument variable, I only get the whole document ...

XDocument.Descendants(itemName) - Problems finding qualified name

Hello, this is my first post here - usually i'll find the answer somewhere in this board - but not today :-( okay: I,m trying to read a XML-RSS-Feed from a website. Therefore i use a async download and create a XDocument with the XDocument.Parse() Method. The Document intends to be very simple, like this: <root> <someAttribute></S...