Quickly create XML in C# VS VB.net

46 views Asked by At

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.

0

There are 0 answers