0

I have the following content in my XML file:

<SOAP:Body>
  <si:myId>
   43h4b-12s22-gj3ls
  </si:myId>
</SOAP:Body>

What I want to do is extracting the name of the XML tag as a whole (ex: "<si:myId>").

However, I can not achieve that with C#. The maximum that I can do is to extract the "LocalName", which is "myId" as shown in the example below:

foreach(var element in xDocument.Descendants()) 
{
    string name = element.Name.LocalName; // ex: myId
}

I would be very happy if you would help me to get the tag with full name (ex: "si:myId").

Niyazi Babayev
  • 120
  • 2
  • 9
  • 1
    Use [`XElement.GetPrefixOfNamespace(XNamespace)`](https://learn.microsoft.com/en-us/dotnet/api/system.xml.linq.xelement.getprefixofnamespace) as shown in [this answer](https://stackoverflow.com/a/6422306/3744182) by Chau to [C#: How to get the name (with prefix) from XElement as string?](https://stackoverflow.com/q/6387726/3744182). In fact I think this is a duplicate, agree? – dbc Dec 07 '22 at 09:02

0 Answers0