0

I have a XML in the following format:

<break name="Chapter01">
<!--Chapter 1-->
<p class="para">Some value</p>
</break>
<break name="Chapter02">
<!--Chapter 2-->
<p class="para">Some value</p>
</break>
<break name="Chapter03">
<p class="para">Some value</p>
</break>

When I am loading the file using XDocument.Load(fileName), all the comments are gone.

It is becoming:

<break name="Chapter01">
<p class="para">Some value</p>
</break>
<break name="Chapter02">
<p class="para">Some value</p>
</break>
<break name="Chapter03">
<p class="para">Some value</p>
</break>

How do I preserve the comments when reading the file using XDocument.Load()?

Clemens
  • 123,504
  • 12
  • 155
  • 268
  • 1
    *"It is becoming"* - what becoming? How do you produce second output exactly? – Sinatr Jun 12 '19 at 08:29
  • As soon as `XDocument.Load(fileName)` is executed, the comments are gone in the `XDocument` variable. Also, the possible duplicate question is not really what I need. I have done all the things needed to be done and now it is a new feature request that I read from comments as well. – Rahul Chaurasia Jun 12 '19 at 08:33
  • 2
    I tested your text with `XDocument.Parse` - and everything is fine. Perhaps, there's something is going on we don't see. – JohnyL Jun 12 '19 at 08:36

1 Answers1

-3

You could try loading the file without XDocument and load it normally and then make a REGEX expression.

SeverinCH3047
  • 121
  • 1
  • 6
  • 2
    `XDocument` can read comments, see [XComment](https://learn.microsoft.com/en-us/dotnet/api/system.xml.linq.xcomment?view=netframework-4.8). – Sinatr Jun 12 '19 at 08:30