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
1 answer

How to prevent XElement from decoding character entity references

I have an XML string that contains an apostrophe. I replace the apostrophe with its equivalent & parse the revised string into an XElement. The XElement, however, is turning the ' back into an apostrophe. How do I force XElement.Parse to preserve…
Mark Maslar
  • 1,121
  • 4
  • 16
  • 28
0
votes
1 answer

Edit resource file C#

I added to my c# project an XML file as a Resource file (Resources -> Add Resource (down arrow) add existing file.) I am reading from the file with no problems : static XElement resource; static List allPageType; static public…
MoShe
  • 6,197
  • 17
  • 51
  • 77
0
votes
1 answer

EF code first 4.1 xml XElement

How do I go about mapping an xml table column to an XElement property in a POCO object. Is there a way to map it using a complex type, or supply the EF framework with a conversion function of some kind so that I can use XElement as the property type…
Jim
  • 14,952
  • 15
  • 80
  • 167
0
votes
1 answer

How to apply a DataTemplate to a XElement subclass?

when I subclass from XElement, the DataTemplate that works for XElement using the element name as DataType, doesn't work for the subclass. Any idea?
SergioB
0
votes
1 answer

C# Find XElement Descendant based on multiple attributes

I have to add information to an existing XML file. The data is going to be underneath an existing node. This has to do with Patient data, and I have to find the existing patient within the XML, so I can add the subsequent data to it. This data is…
0
votes
0 answers

Bypassing notfound error with System Xelement

void SaveKurByDayAsync(DateTime firstDay , DateTime lastDay) { List dateList = new(); for (DateTime date = firstDay; date <= lastDay; date = date.AddDays(1)) { dateList.Add(date); } foreach (DateTime date in…
0
votes
1 answer

XPath and XNodes vs Xelements, whats better for mapping two large xml documents?

I want to map two fairly large xml documents, one of them using the NIEM schema. I am most familiar with the System.Xml.Linq (XElement) class but have heard good things about using XPath and XNodes, contained in the System.Xml namespace. Anyone…
Meyer Denney
  • 796
  • 1
  • 11
  • 34
0
votes
0 answers

Receive object reference error when iterate the xdocument to retrieve xml element value

Dim lstrReadXml As String = String.Empty mobjComFun.ReadTextFile(System.Windows.Forms.Application.StartupPath & "\GoFirstBookingXML\GetBookRes.xml", lstrReadXml) Dim lobjXdoc As XDocument = XDocument.Parse(lstrReadXml) Dim lobjNs As New…
Naresh
  • 1
  • 2
0
votes
1 answer

How to replace Xml Attribute Prefix value by using C#

Table 2 Model fit cnbs for the span targeted moments.
0
votes
0 answers

XElement Linq query to count number of decendant elements that match attribute value

I'm trying to find the number of child elements of where the 'index' attribute matches '2'. I'm expecting an integer value of 2. My code compiles but generates an error at runtime. My xml looks like this.
Darryl
  • 11
  • 4
0
votes
2 answers

c# SqlDataReader to XElement Efficiently

I have a Sql SP that takes around 1 minute to run, returning 25,000 rows of data. (multiple datasets can be returned). Currently trying to convert this into an XElement/XDocument to produce several reports results in the c# method converting this…
ct5845
  • 1,428
  • 3
  • 16
  • 20
0
votes
0 answers

Merging the XElement Parent-Child Name and Value Programmatically using Linq to Xml

From this XML with around 10,000 records: Tomato 1
RickyBelmont
  • 619
  • 4
  • 11
0
votes
2 answers

NullReferenceException while using XElement

I have a method that is suppose to edit a xml file: public void EditItem(Item item, string xml) { Data = XDocument.Load(HttpContext.Current.Server.MapPath("~/App_Data/Items/" + xml + ".xml")); XElement node =…
Kasper Skov
  • 1,954
  • 10
  • 32
  • 53
0
votes
0 answers

How do I address this exception when reading data using XElement?

I am trying to populate my own object from a XElement: MidweekMeetingHistoryItem oItem = new MidweekMeetingHistoryItem { Week = datHistoryItemWeekOfMeeting, Chairman = nodeHistoryItem.Element("Chairman")?.Value, AuxCounsellor1 =…
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
0
votes
0 answers

WEB API dot net 6 my controller returns XElement so don't need serialisation

I have an old web API that build directly XML as XElement. I want to switch to ASP.NET core 6 web api but I want to return the same XML as before. So I don't need serialisation I want to return directly my XElement What must I do ? Jean