Click here to Skip to main content
15,914,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create an XML like this using C#

<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_SLM_softwareCostRate xmlns:ns0="urn:DPS:SoftwareCostRate:SLM_To_S4">
   <SLM_SoftwareDetails>
      <SW_Name>MS Visio</SW_Name>
      <SW_Licence_Type>Perpetual</SW_Licence_Type>
      <SW_Cost>100</SW_Cost>
      <Currency>USD</Currency>
      <Year>2020</Year>
      <Month>DEC</Month>
   </SLM_SoftwareDetails>
</ns0:MT_SLM_softwareCostRate>


How do I add
ns0:
in the tag?

What I have tried:

writer.WriteStartElement("MT_SLM_softwareCostRate");
               writer.WriteAttributeString("xmlns", "ns0", null, "urn:DPS:SoftwareCostRate:SLM_To_S4");
writer.WriteStartElement("SLM_SoftwareDetails");
                   writer.WriteElementString("SW_Name", "Test");
                   writer.WriteElementString("SW_Licence_Type", "Test"));
                   writer.WriteElementString("SW_Cost", "Test");
                   writer.WriteElementString("Currency", "Test");
                   writer.WriteElementString("Year", "Test");
                   writer.WriteElementString("Month", "Test");
Posted
Updated 24-Jan-20 0:16am
v2

1 solution

There are examples in the documentation

XmlWriter Class (System.Xml) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900