0

I am redoing a legacy VB.Net app in MVC. Part of the app used MSXML2 to create an XML document. I am having trouble with two elements so far. The legacy code uses "Right" (Right Function in C#?) and "Format" (Equivalent of Format of VB in C#) commands.

Is there a preferred method for creating the XML other than using System.XML?

objNode = objDoc.CreateNode("element", "Payout", "");
objElement = objDoc.DocumentElement.AppendChild(objNode);
objElement.SetAttribute("companyNumber", Right(objRs.Fields["operating_unit_code"].Value, 3));
objElement.SetAttribute("employeeNumber", objRs.Fields["employee_code"].Value);
objElement.SetAttribute("earningsCode", objRs.Fields["incentive_type_code"].Value);
objElement.SetAttribute("chargeToProject", Right(objRs.Fields["operating_unit_code"].Value, 3) & objRs.Fields["organization_code"].Value);
objElement.SetAttribute("amount", Format(objRs.Fields["sum_calc_amount"].Value, "#.00"));
objElement.SetAttribute("weekEndingDate", Format(objRs.Fields["pay_period_end_date"].Value, "MM/DD/YYYY"));
objElement.SetAttribute("employeeName", objRs.Fields["full_name"].Value);
Community
  • 1
  • 1
Kevin Schultz
  • 886
  • 3
  • 20
  • 42

1 Answers1

2

XDocument and Linq to XML is very popular way of creating XML. XDocument or XmlDocument contains a good reasons for one or another.

If you are porting VB.Net code it already using XmlDocument (or other implementation of XML DOM API) it is likely easier to keep using it to minimize changes. You may even get away with simply decompiling that assembly or particular methods into C# code (i.e. using ILSpy or R#).

Note: MSXML2 (or any other version) is not supported in managed applications, so using it is not really an option.

Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179