0

Here I wish to add a namespace to the forst line of xml document i.e

<?xml version="1.0" encoding="utf-8"?> 

I am creating the xml file using c# with the help of syndicate rss feed. it should be like

<?xml version="1.0" encoding="utf-8" xmlns:example="www.example.com ?> 
Madhav
  • 559
  • 2
  • 11
  • 34
  • 1
    The namespace should be added to the root tag and not the identification line. – jdweng Jul 26 '17 at 13:11
  • another good post https://stackoverflow.com/questions/7601759/c-sharp-add-xml-namespace-xmlns-tag-to-document – Rahul Jul 26 '17 at 13:16
  • That line is called the XML Preamble. –  Jul 26 '17 at 13:16
  • Hello will,the question is different i think because i have a different scenario – Madhav Jul 26 '17 at 13:16
  • @Ma6139735 The solution to the marked question answers this one. The different "scenario" is irrelevant. –  Jul 26 '17 at 14:04
  • but why you were in so hurry?to mark it as a duplicate question, you could suggest to update it?don't you? – Madhav Jul 27 '17 at 12:07

1 Answers1

1

You can use the xmlns attribute to add the namespace like

doc.DocumentElement.SetAttribute("xmlns", "www.example.com");
Rahul
  • 76,197
  • 13
  • 71
  • 125