xelement

Inserting Variable into Inline XML in VS2008

so i have some inline XML Dim x As XElement = _ <parent> <child></child> </parent> what I want to do is get some variables that have been set into that xml Dim v as string = "Blah" Dim x As XElement = _ <parent> <child>{v}</child> </parent> Is this possible? I...

Reading xml stream

Sorry to be asking such similar question again, I am trying to read the following XML document: <markets currency="GBP"> <market id="2908368" nextId="2908395"> <status>ACTIVE</status> <commissionRate>2.5</commissionRate> <marketType>ANY_NUMBER_OF_WINNERS</marketType> <selections type="MainBets"> <selection id="65...

Inserting records into an XML table with a unique key

Hi, Maybe I'm just spoiled by SQL, but is there some cool LINQ way to insert a new record into an "XML table" and have the indexed ID update automatically (or at least semi-automatically)? Here's what I mean by "XML table": <myElements> <myElement> <id>1</id> <value>blah</value> </myElement> <myElement> <id>...

XElement default namespace on attributes provides unexpected behaviour

I am having trouble creating an XML document that contains a default namespace and a named namespace, hard to explain easier to just show what I am trying to produce... <Root xmlns="http://www.adventure-works.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:SchemaLocation="http://www.SomeLocatation.Com/MySchemaDoc.xsd"&gt;...

How can a WCF XElement Response include the XML Declaration?

I have a WCF service that is returning an XElement, this is working fine however I would like it to include the XML Declaration in the response: <?xml version="1.0" encoding="utf-8"?> The client side is not something that I can change and is reporting a "Result is not XML" The only other differences between the response of my HTTP re...

How to add an existing Xml string into a XElement

How to add an existing Xml string into a XElement? This code var doc = new XDocument( new XElement("results", "<result>...</result>") ); of course produces this <results>&lt;result&gt;&lt;/result&gt;</results> but I need this <results><result>...</result></results> Any ideas? ...

XElement vs Dcitionary

Hi All, I need advice. I have application that imports 10,000 rows containing name & address from a text file into XElements that are subsequently added to a synchronized queue. When the import is complete the app spawns worker threads that process the XElements by deenqueuing them, making a database call, inserting the database output ...

how to add(or ignore) XML namespace when using XElement.Load

I am creating XML using Linq to XML and C#. It all works great except when I need to manually add in a row in the XML. This row is only added if I have a value to pass through to it, otherwise I just ignore the entire tag. I use XElement.Load to load in the string of text that I store in a string but when I attach it to the XML it alway...

parsing XML with ampersand

I have a string which contains XML, I just want to parse into Xelement, but it has an ampersand. I still have problem to parse it with HtmlDecode. Any suggestion? string test = " <MyXML><SubXML><XmlEntry Element="test" value="wow&" /></SubXML></MyXML>"; XElement.Parse(HttpUtility.HtmlDecode(test)); I also added these methods to rep...

Removing XElements in a foreach loop

So, I have a bug to remove foreach (XElement x in items.Elements("x")) { XElement result = webservice.method(x); if (/*condition based on values in result*/) { x.Remove(); } } The problem is that calling x.Remove() alters the foreach such that if there are two Elements("x"), and the first is removed, the loop d...

Deserializing using XElement

I had to write my own deserializer, because XmlSerializer and DataContractSerializer aren't good for my needs. So, here's the base of my deserializer: static BaseElement ParseXml(XElement element) { var e = (Element)Activator.CreateInstance(Type.GetType("Elements." + element.Name)); foreach (var attr in element....

How can I write XML output?

How can I see the XML output of following C# code? I can see that it uses XElement, but where I can locate the XML file or the output? private void Form1_Load(object sender, EventArgs e) { XElement doc = new XElement("searchresults"); // root element //create XElement result = new XElement("result", ...

Is LINQ to XML's XElement ordered?

When I use LINQ to XML, is the order of the elements and attributes written out to text guaranteed to be the same order as how I added the XElement and XAttribute objects? Similarly, when I read in an XML document, is it traversed in the same order as it appears in the XML? ...

XElement.Descendants("Node") not behaving as expected, returns multiple levels of Descendants

Hello, I have an issue. I have hierarchical XML data such as: <Tree> <Node Text="Stuff" ItemGUID="064a9bf0-0594-47f8-87be-88dd73763c77" > <Node Text="Food" ItemGUID="326f1f7a-d364-4838-9bdc-ce5fd93f88ca" ItemType="2" /> <Node Text="Wines" ItemGUID="950e3ca3-27a1-41fd-89f3-7a8b08633a9f" /> <Node Text="Flowers" ItemGUID="ce...

Checking an XElement for Existence of One of Several Possible XElements

Is there a way to determine if an XElement contains one of any specified elements? For example, I have XElements that I'll want to check: Dim xe1 = <color><blue/></color> Dim xe2 = <color><red/></color> Dim xe3 = <color><powderBlue/></color> Dim xe4 = <color><aqua/></color> Dim xe5 = <color><green/></color> I'd like to be able to quer...

XML XElement / Linq replace values with data from dictionary...

Is there a way to replace all existing values from XML with values from dictionary using Linq? I'm using c#. XML example: <root> <node1> <--without attribute <subNode1>someTextValue</subNode1> </node1> <node2 name="myNode2"> <--With attribute (IMPORTANT!!!) <subNod1>someOtherTextValue</subNode1> </node2> </root> Dicti...

How to write System.Xml.Linq.XElement using XmlWriter to a stream.

Dear ladies and sirs. I have an XElement instance and I wish to write to a stream using XmlWriter class. Why? Well, one of the configuration settings defines whether to use binary Xml or not. Based on this setting a suitable XmlWriter instance is created - either by XmlWriter.Create(stream) or XmlDictionaryWriter.CreateBinaryWriter(stre...

c# writing excel file as xml...

I'm writing an xml file to be consumed by excel. excel wants this: <Cell><Data ss:Type="Number">25</Data></Cell> I'm writing this... <Cell> <Data ss:Type="Number">25</Data> </Cell> I get that EXCEL is picky, but since I'm using XElelments, how do i control the formatting of the output? here is my code to write a cell. foreach...

How do I configure WCF client to use XElement and not XmlDocument?

I have an ASMX webservice that returns XElement - (not an .svc WCF service) When consuming the service in Silverlight the client that is generated uses XElement as I want. However in C# .NET 3.5 WCF 'Service Reference' it generates this property using XmlDocument. In C# .NET 4 WCF 'Service Reference' it also generates this property us...

WCF Can't Return XmlElement from XmlDataDocument.DocumentElement

Hi guys, I'm building a WCF web service which returns a composite object that looks similar to the following: [DataContract] public class WebServiceReturn { ... [DataMember] public XmlElement Results { get; set; } ... } When I return a WebServiceReturn object with the following code, e...