Questions tagged [xelement]

XElement is part of System.Xml.Linq in .NET Framework. This class represents an XML element, the fundamental XML construct.

An XElement has an XName, optionally one or more attributes, and can optionally contain content.

An XElement can contain the following types of content:

  • XElement
  • XComment
  • XProcessingInstruction
  • XText

Reference: XElement Class on MSDN

883 questions
0
votes
2 answers

Is there a difference between el.Attribute ("...") and el.Attribute (XName.Get ("..."))?

In our production code, I've seen XML attributes being read using explicit XName.Get call: var name = element.Attribute (XName.Get ("name")); I used to always pass a string to Attribute: var name = element.Attribute ("name"); This is more readable…
Dan Abramov
  • 264,556
  • 84
  • 409
  • 511
0
votes
2 answers

How can I remove an unwanted node from a list of XElements?

I need to use C# to manicure the response from a service before handing it off to the caller. The service takes a series of requests in XML format, formats the message and send it to the service. The response looks similar to this:
DaveN59
  • 3,638
  • 8
  • 39
  • 51
0
votes
0 answers

C# XElement how do I add different attributes in a specific order?

I have the following C# code to generate an XML document. The problem is that I need to swap the order of the attributes in the tag "CState". Therefore I have already tried several things. Unfortunately it does not work or I get an…
ThoDan
  • 43
  • 4
0
votes
4 answers

The best way to retrieve the attributes from xml elements using C#/.net 3.5

If we have a XML like:
Sri Reddy
  • 6,832
  • 20
  • 70
  • 112
0
votes
1 answer

Calculate Length of XElement that is not Wasteful?

I have a large XElement property, and want to know the byte size of it for logging purposes. I don't want to just ToString() it because I have concerns about potentially big strings (not) getting GC'd. What is a smart/compact way to calculate the…
Snowy
  • 5,942
  • 19
  • 65
  • 119
0
votes
1 answer

Add to List from XElement in foreach loop

Program.cs using ConsoleApp2.Models; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string City_Name =…
larsx
  • 3
  • 2
0
votes
1 answer

Unable to find root node while parsing xml using XElement - Windows Phone 7

I have moved into parsing XML files in WP7 and until now was finding it quite straightforward. My current XML is something like this :
0
votes
0 answers

Why is XElement adding my new XElement in the wrong place

I'm written a program that builds an XML structure (conforming to a specific schema) from a Word document. All is good apart from a small bug which is driving me mad. If the Word doc has a 'para' directly after a sequencial list (numbered list), the…
Daedalus
  • 539
  • 2
  • 6
  • 16
0
votes
0 answers

How to add attribute in Datamember c#?

How to add attribute to data Member? Current datamember: [DataMember(Order = 18, Name = "shippingAddress")] public SubscriptionAddressOut ShippingAddress { get; set; } This is my current output:
Techgeeks1
  • 556
  • 1
  • 4
  • 18
0
votes
1 answer

Get XElement with XPathSelectElement

I have a XML file and loaded the specific tag to an XElement. From this XElement in want to give a path to get the specific child element. I don't wan't to use the Descendates() method. I tried using XPathSelectElement to get the job…
Max
  • 62
  • 1
  • 7
0
votes
3 answers

Insert XML element using LINQ

I got a problem when insert XML element using LINQ. This is my program: XDocument doc; protected void CreateXml() { doc = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XComment("Sample RSS Feed"), new…
Chelsea_cole
  • 1,055
  • 3
  • 15
  • 21
0
votes
1 answer

How to convert Dictionary into xml file?

Dictionary Dictionary _XParents = new Dictionary(); My dictionary looks like: key:, value: I want to convert this dictionary to XML file XML should look like:
0
votes
2 answers

Parse xml response with XElement into Model class

I have the following class: public class Location { public string Name { get; set; } public long Latitude { get; set; } public long Longitude { get; set; } public string AddressLine { get; set; } public string FormattedAddress {…
Brett
  • 1,923
  • 3
  • 18
  • 24
0
votes
1 answer

How to use For loop inside XElement

I try to create an XML document from a recieved List which T is the type of the list. so, the problem is when I try to use a for loop inside XElement I get errors. My idea is ccreating an XML Document contains elements based on the T…
XDev
  • 125
  • 1
  • 8
0
votes
0 answers

Changing from FileInfo to XElement and needing to stream the data

My old signature was protected override bool SendFiles(ITransactionStep configuration, FileInfo xml) Thus I was working with doing this using (var blobStream = GetBlobStream(arg.Configuration, arg.WorkspaceContext, arg.TempFile.Length, out var…