2

I made a module a while back that I used to create XML in VB.net. In this time, it was only in VB.net that you could do something that easily:

Dim completeXML = <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
                  <?xml-stylesheet href="inventaire.xsl" type="text/xsl"?><HF_DOCUMENT>
                  <%= From P As GestionInventaire.DAL.vInventaire In produits
                      Select
                          <REQ_Inventaire_Produit_Exporte>
                              <NumClient><%= P.T_Ref_Produit.T_Ref_Client.Seq.ToString() %></NumClient>
                              <Societe><%= P.T_Ref_Produit.T_Ref_Client.Nom %></Societe>
                              <CodeProduit><%= P.CodeProdut %></CodeProduit>
                              <DescriptionProduit><%= P.Desription %></DescriptionProduit>
                              <DimensionProduit><%= P.Dimensions %></DimensionProduit>
                              <QteMini><%= P.T_Ref_Produit.QteMinimumB.ToString() %></QteMini>
                              <QteMax><%= P.T_Ref_Produit.QteMaximumB.ToString() %></QteMax>
                              <PrixUnitaire><%= P.T_Ref_Produit.PrixUnitaire.ToString("0.00").Replace(",", ".") %></PrixUnitaire>
                              <NbPaquets><%= P.NbPaquet.ToString() %></NbPaquets>
                              <PceCount><%= P.T_Ref_Produit.QtePaquet.ToString("0.00").Replace(",", ".") %></PceCount>
                              <Emplacement><%= P.Emplacement %></Emplacement>
                              <Location><%= P.SiteParent %></Location>
                              <QteMiniHiver><%= P.T_Ref_Produit.QteMinimumA.ToString() %></QteMiniHiver>
                              <QteMaxHiver><%= P.T_Ref_Produit.QteMaximumA.ToString %></QteMaxHiver>
                              <AncienCode><%= P.T_Ref_Produit.AncienCode %></AncienCode>
                          </REQ_Inventaire_Produit_Exporte>
                  %>
                  </HF_DOCUMENT>

As you can see, I simple enter XML tags with <% %>, much like in Razor to create the XML.
Considering VB.net is no longer available in .Net Core, is there any equivalent in C#?

Mind you, I know we can get the same result by using XDocument objects and by looping through object, but this method is so quick to implement and easy to read, I really like it.

GSerg
  • 76,472
  • 17
  • 159
  • 346
David Brunelle
  • 6,528
  • 11
  • 64
  • 104
  • 1
    c# does not have xml literals like VB.NET – Crowcoder Jul 09 '20 at 20:16
  • That was from a project made almos 6 years ago, I was expecting it should put it in C# in some way since then... :( – David Brunelle Jul 09 '20 at 20:26
  • 1
    `Considering VB.net is no longer available in .Net Core` - it is currently available for class library and console projects, which [will improve with .Net 5](https://devblogs.microsoft.com/vbteam/visual-basic-support-planned-for-net-5-0/). Create a vb.net class library, move all XML related tasks into it and reference it from the main C# app. – GSerg Jul 09 '20 at 20:28
  • 1
    ["*Never! We won't bake in a specific format.*"](https://github.com/dotnet/roslyn/issues/3912), signed Mads Torgersen – Crowcoder Jul 09 '20 at 20:31

0 Answers0