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

Accessing XElement's attribute with Linq

I'm parsing an XElement object like this one XElement teachers = new XElement("Teachers", new XElement("Teacher1", new XAttribute("Age", 27)), new XElement("Teacher2", new XAttribute("Age", 60)), new…
MaPi
  • 1,601
  • 3
  • 31
  • 64
0
votes
1 answer

How to get values of XElements from more than one Descendants in Windows Phone 8

How do I get XElements values from more than one Descendants See my XML Document: 21 Photo
Nitesh Kothari
  • 890
  • 12
  • 27
0
votes
1 answer

Loop through XElement and remove some tags

please consider this code: public static XElement ToXElement(this object obj,List JustThisProperties) { using (var memoryStream = new MemoryStream()) { using (TextWriter streamWriter = new StreamWriter(memoryStream)) …
Arian
  • 12,793
  • 66
  • 176
  • 300
0
votes
2 answers

Add Parameter to XElment on Runtime C#

I am creating a XML String by collection of attributes but i struck in one thing. I want to add different XElement Parameter at runtime on the basis of value exist or not. In the following code i am sending different parameters to constructor of…
Zaid Iqbal
  • 1,662
  • 5
  • 25
  • 45
0
votes
1 answer

How To remove a specific tag from XElement

Please consider this XML: 1000 Nima Agha 1002 Ligha Ligha
Arian
  • 12,793
  • 66
  • 176
  • 300
0
votes
1 answer

Querying XElement in a Xamarin Android App

The method I have been using to query an XElement works in Windows but not in Xamarin Android: using System.Xml; using System.Xml.Linq; using System.Linq; public string ValidateLicense() { XElement xEl; string sMessage; …
james pearce
  • 355
  • 1
  • 5
  • 20
0
votes
2 answers

How to read XML header information using Linq to XML

I am trying to figure out how to use Linq to XML to read an XML file into my C# program. Here is the example for my question: How do I…
MatthewHagemann
  • 1,167
  • 2
  • 9
  • 20
0
votes
1 answer

How to parse an ArrayOfXElement in Windows Phone?

I'm trying to connect to an ASMX web service and the code generated in a Windows Phone Project is different than in Windows Forms. In Windows Forms, the methods of this web service returns a DataSet, so I go through all rows in the existing tables…
wm1sr
  • 1,905
  • 1
  • 16
  • 20
0
votes
1 answer

Reading large Xml files downloaded from a zip and loaded into MemoryStream

I am reading very large Xml files (400+ MB), 15 MB zipped that is downloaded and unzipped into MemoryStream. I am running into a System.OutOfMemoryException every time. I tried using StreamReader.ReadToEnd() and read it to a string, doesn't…
Kyle
  • 5,407
  • 6
  • 32
  • 47
0
votes
0 answers

How to use Xelement in this situation

I have to obtain this kind of xml : name1 CB 0 sep1
Sss
  • 1,519
  • 8
  • 37
  • 67
0
votes
2 answers

LINQ to XML filter descendants C#

I have xml that is sent by a third party and I want to validate it. XElement xTree = XElement.Parse(@" Donny
0
votes
2 answers

WCF - reading an xml file in a service using XElement.Load

i have a simple xml file in a wcf service that i am trying to load using Xelement.Load("sample.xml") which is not reading the file. What's the right way of doing this? The service is supposed to return an xml to an asp.net application. TIA
SoftwareGeek
  • 15,234
  • 19
  • 61
  • 78
0
votes
1 answer

WPF Bind DataGrid to XElement Attribute value

Im trying to bind some XML data to a DataGrid, the code is working fine, but i can't bind to attribute values.
user1359448
  • 1,539
  • 3
  • 14
  • 23
0
votes
1 answer

if else statement in XElement

I am wondering, how can I add a new XElement by using a if/else statement? For example... XDocument document = XDocument.Load(this.XMLFile); document.Element("currentjobs").Add( new XElement("job", new XElement("date",…
Kyle
  • 53
  • 7
0
votes
1 answer

issue with XElement.Save method and carriage return

i have this simple code: var xel=new XElement("myElement"); xel.Value="\r"; // assign carriage return xel.Save(@"file.xml",,SaveOptions.DisableFormatting) If i open the file with notepad++ and i show all chars, i see that the element value is saved…
stefano m
  • 4,094
  • 5
  • 28
  • 27