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

XML Linq - find a value of XElement from nested Descendants

I have a sample of the following XML response from a REST call
0
votes
1 answer

Adding a string to a list only if it is not empty (from XElement)

Sample code: public string[] GetMeetingPersonnel(DateTime dateMeeting, string strHistoryDatabase) { DateTime dateMonday = dateMeeting.StartOfWeek(DayOfWeek.Monday); XDocument docAssignHistory = XDocument.Load(strHistoryDatabase); string…
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
0
votes
0 answers

LINQ remove method leaves a empty tag in xml

I am looking for a good approach to write a LINQ query that can preserve empty tags in XML. Input XElement:
0
votes
0 answers

Remove multiple namespaces from XML with C#

My XML having multiple namespaces. I want clean XML just with tags only. Here is my XML:
Damini Suthar
  • 1,470
  • 2
  • 14
  • 43
0
votes
1 answer

Is it possible to convert this foreach loop into a LINQ-to-XML loop?

I originally asked this question (Can we automatically add a child element to an XElement in a sortable manner?) and it was closed as a duplicate (how to add XElement in specific location in XML Document). This is teh code that I have at the…
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
0
votes
0 answers

Problem with using DateTime.ParseExact with a text string in the format "WyyyyMMdd"

I am trying to parse into a string: DateTime datWeekDB = DateTime.ParseExact(weekDB.Value, "WyyyyMMdd", CultureInfo.InvariantCulture); The text strings are like, eg: W20220120 But this is failing:
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
0
votes
0 answers

Can we automatically add a child element to an XElement in a sortable manner?

I have seen this similar question on sorting XElement data (Sorting all the elements in a XDocument). In my case I am only interested in the first level of children of the root node in the XDocument being sorted. But, assume that the data is already…
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
0
votes
1 answer

Simple binding of XML data to WPF TreeView using XElement

Its been a while since I've had to mess with the syntax to actually hook up an XML data set using XElement to a WPF TreeView. I've tried to recreate a pretty simple example, but I get nothing displaying in the TreeView. Here is my…
Ultratrunks
  • 2,464
  • 5
  • 28
  • 48
0
votes
0 answers

XElement and value for boolean attributes

Take for example: new XAttribute("Completed", true) studentElement.SetAttributeValue("Included", studentItem.Type != string.Empty); In both instances, the resulting XML file will have ether "true or "false". Is it possible to set up the…
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
0
votes
2 answers

Conditionally adding a XElement to a new XElement using c~

I am trying to use XElement to add new content to an existing XML data file. For the most part it is working OK but I need to change it. This is what I have so far: xdoc.Root.Add( new XElement("W" + record.Date.ToString("yyyyMMdd"), new…
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
0
votes
0 answers

XmlTextReader An error occurred while parsing EntityName c#

I am trying to read an XML file containing special characters: 1 0 0 100 0 1 Using the below logic, where stream is coming from an xml file: using…
Elias Ghali
  • 823
  • 1
  • 13
  • 29
0
votes
0 answers

Cannot create XML where the XElement value contains ":"

I have the following code: private string GetXmlBody() { XNamespace ns = "http://schemas.xmlsoap.org/soap/envelope/"; XNamespace xsdNs = "http://www.w3.org/2001/XMLSchema"; XNamespace xsiNs =…
so cal cheesehead
  • 2,515
  • 4
  • 29
  • 50
0
votes
1 answer

Retrieve list of xml tag of child nodes in linQ to xml

I'm trying to get all the list of the different child nodes (not starting from root) of a loaded XML into a list of strings, I had done using System.Xml library but I want to write the same code with LINQ to XML too. I had found a code that helped…
Simone
  • 1
  • 1
0
votes
1 answer

How to access this nested XElement?

hopefully you can help, this is the SOAP response message that I'm trying to read data from:
Kyle Mann
  • 17
  • 3
0
votes
1 answer

How to filter elements from XML file

I can read a xml file to the console. But I need only some elements from the xml file. Like Sender Name, Postalcode, weight and value. Because now all the element from the xml file are returned.
mightycode Newton
  • 3,229
  • 3
  • 28
  • 54