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

C# XML Linq, reading XML returns NullReferenceException

Firstly, I am sorry - I have searched and searched, tried example after example, answer after answer and after trying lots of different examples, I still cannot get this to work for myself. I have an XML smoething like this:
0
votes
1 answer

Child nodes ONLY of an XElement

Using XLinq, you seem to have to know the exact name of an element's children to access specific child elements. I want to access/discover the immediate children of an element recursivly without such tight coupling. if I…
0
votes
1 answer

adding Xelement according to specific condition c#

I have this XML code, i would like to insert a child node according to a specific condition of another node.
Amd Whb
  • 25
  • 4
0
votes
1 answer

Retrieve XElement's children as top level of object

When using the XElement API and asking for a particular element (via .Element("Foo")), I get back an object which, when serialized to JSON (using ASP.NET Core), results in an object with a single field (Foo), which then contains all of the child…
Simon Morgan
  • 2,018
  • 5
  • 23
  • 36
0
votes
1 answer

XML Edit to file using C#

I am working on a WPF application and I have a simple XML file that I am parsing using 'XmlDocument' and is working fine for the readinh part. I want the use to be able to add, edit or delete any node and save these changes to the file. I tried…
Hasan H
  • 142
  • 11
0
votes
1 answer

C# getting last element's attribute values from XML

I have below XML. I dont need first…
thatthing
  • 676
  • 3
  • 15
  • 39
0
votes
1 answer

How to get the last XElement of particular type C#, XML, LINQtoXML

I've come across different ways of getting the last element (there are several elements and two other but only the last element is the target needed) on the following link, e.g.: XDocument xDoc = XDocument.Load("Source.xml"); …
user12998935
0
votes
2 answers

Delete an xelement with no child element

The structure of my XML using XElement looks like this. I am using XElement in XDocument
[...]
hopeforall
  • 401
  • 1
  • 6
  • 20
0
votes
0 answers

Adding xsl:nil to XElement

This is really starting to wind me up. I've tried searching all over the net with this but it seems people only want to consume XML files, not build them :S. I'm building an XML file which needs to be compliant with an .xsd referencing the…
Adamski343
  • 39
  • 9
0
votes
1 answer
0
votes
0 answers

How do I get the previous XElement sibling with matching conditions

I've got some data that comes in XML format, and which contains a list of items:
Unapedra
  • 2,043
  • 4
  • 25
  • 42
0
votes
1 answer

How do I cast a XElement as string in c#?

Here is my code: SqlConnection conn4 = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=test_BdbCSSQL01;Persist Security Info=False;Integrated Security=SSPI;"); conn4.Open(); string sql = "SELECT * FROM…
Zach
  • 329
  • 1
  • 3
  • 8
0
votes
3 answers

Transfer the local name of a XML XElement to string

Hy at all, i am new in C# programming so maybe this is a easy question. I try to read an XML-file with XDocument and write out the local name of a Element as string. For the output i use the listing window of SiemensNX but every other output window…
MarcelM
  • 29
  • 4
0
votes
2 answers

select XElements with xmlns

How do you select an element with xmlns specified? I need to select Include/Fragment element. I've tried adding http://schemas.microsoft.com/wix/2006/wi before element names, but that doesn't work. In XmlDocument there was NamespaceManager…
Bogdan Verbenets
  • 25,686
  • 13
  • 66
  • 119
0
votes
1 answer

VB.Net XElement: specific attribute from combobox looping through XML

I want the value of a specific attribute (e.g. title_1 in my html example) which I select with a combobox in visual studio. I have a problem with my looping through the attributes. It works only with title_1 and stops after the title_1. Following my…
lynx
  • 3
  • 3