xelement

How to dynamically set local XML namespace?

I have several xml namespaces that expose the same schema. I want to use a function that dynamically accepts a namespace and applies the attributes or the properties according to the specified namespace: Public Sub ProcessElement(element As XElement, [namespace] As XNamespace) element.<[namespace]:Property>.Remove() End Sub I actua...

How to use XPath with XElement or LINQ?

Consider the following XML: <response> <status_code>200</status_code> <status_txt>OK</status_txt> <data> <url>http://bit.ly/b47LVi&lt;/url&gt; <hash>b47LVi</hash> <global_hash>9EJa3m</global_hash> <long_url>http://www.tumblr.com/docs/en/api#api_write&lt;/long_url&gt; <new_hash>0</new_hash> </data> </response>...

Find the delta between two xelements using "except" C#

My first XElement is: XElement sourceFile = new XElement("source", from o in Version1.Element("folder").Elements("folders").ElementAt(0).Elements("folder") where o.Name != null && o.Name == "folder" select new XElement("data", new XElement("name",(string) o.Attribute("n...

Fluent NHibernate and XML columns

I'm building a new site from scratch and am considering using Fluent NHibernate for my ORM. I think it'll handle everything easily except, possibly, my XML columns. I've never built a site with NHibernate at all (though I've used Hibernate for Java) so consider me a n00b. Ideally I'd like the XML to be treated as an XElement as Linq-to-...

when WCF method returns XmlElement , the client sees XElement returned?

i return an xmlElement from a WCf method. when i do a service reference in the client, the same method is returning XElement instead of XmlElement. i tried everything: updating the service reference, making a new service reference, but it doesn't help. This is my client: ServiceReference1.BasicServiceClient basicWCfClient = new Servic...

How can I store inline HTML in an XText class?

I'm using XElement-related stack of classes to build HTML. One thing I need is the XText element to store raw HTML (e.g., <i>this</i>) without HTML-encoding it. Is there any hack that would let me do it so that when I call ToString() it gives me the expected HTML back? ...

Filtering out duplicate XElements based on an attribute value from a Linq query

I'm using Linq to try to filter out any duplicate XElements that have the same value for the "name" attribute. Original xml: <foo> <property name="John" value="Doe" id="1" /> <property name="Paul" value="Lee" id="1" /> <property name="Ken" value="Flow" id="1" /> <property name="Jane" value="Horace" id="1" /> <property name="Paul" value...

asp.net mvc setting XElement xml to empty

How can I do something like XElement xml =empty; ...

Using For Each loop with a Where Clause for XElement

Hi, I am tring to write a for each loop that loops through the descendants of an xml doc but only the ones that satisfy a criteria. I thought i would be able to do this with the where clause but i am having problems with this. It would be great if someone could let me know if this is actually possible or if there is another way i could...

DataContractSerializer not deserializing all variables

I'm trying to deserialize some xml without having the original class that was used to create the object in xml. The class is called ComOpcClientConfiguration. It's succesfully setting the ServerUrl and ServerUrlHda values, but not rest of them... So what I'm asking is: How can I make the rest of these values get set properly, and why are...

How can i check if this XElement is not null before adding it to an anonymous object?

I'm populating an anonymous object from an XML file. Up until now, commentary.Elements("Commentator") has always had a value so i've never had to check for null. I've had to remove that though, and now it's failing when it tries to read that line. I'm looking at the code and I don't know what to change though, because its being selec...

XDocument: Conditionally create new XElement...

Hi all, My question is regarding conditionally creation of XElements, that is, if some condition is met, create the XElement, if not, skip creating the XElement? At this point of time, I could create empty XElements, and then remove all empty elements, by checking, if IsEmpty is true, but that somehow does not feel right... I feel, tha...

How to loop through a set of XElements?

http://www.dreamincode.net/forums/xml.php?showuser=335389 Given the XML above, how can I iterate through each element inside of the 'lastvisitors' element, given that each child group is the same with just different values? //Load latest visitors. var visitorXML = xml.Element("ipb").Element("profile").Element("latestvisitors"); So no...

Preserve certain nodes when using LINQ to XML

I am having difficulty preserving certain nodes (in this case <b>) when parsing XML with LINQ to XML. I first grab a node with the following LINQ query... IEnumerable<XElement> node = from el in _theData.Descendants("msDict") select el; Which returns the following XML (as the first XElement)... <msDict lexid="m_en_us0000002.001" type=...