I need to encode normal XML file to Fast Infoset XML document. In Nuget package, I installed LiquidTechnologies.FastInfoset package (which is the only one I found)
My XML doc to convert as below
<?xml version="1.0" encoding="utf-8"?> <GomsStockRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" callerMethod="pushInfinityAllocatedStockLevel" transactionType="InventoryJob"> <stockRequestEntry> <productCode>100001</productCode> <availableQuantity>1</availableQuantity> <reservedQuantity>0</reservedQuantity> <inventoryType>Job_Import</inventoryType> </stockRequestEntry> </GomsStockRequest>
There are CR LF and white space characters after transactionType="InventoryJob"> and before the child elements. My destination system is using Java and they can read the Fast Infoset docs encoded by Java as following:
à � xÏ�xsi(http://www.w3.org/2001/XMLSchema-instanceÏ�xsd�http://www.w3.org/2001/XMLSchemað<�GomsStockRequestx�callerMethodH�pushInfinityAllocatedStockLevelx�transactionTypeH�InventoryJobð’ <�stockRequestEntry’� < productCode’�100001ð’� <�availableQuantity�1ð£<�reservedQuantity�0ð£<inventoryType’�Job_Importð’� ð� ÿ
which preserved the whitespace and maybe just ignore the CR char.
However, for me, using C#, the result after write out Fast Infoset doc as following:
à � xÏ�xsi(http://www.w3.org/2001/XMLSchema-instanceÏ�xsd�http://www.w3.org/2001/XMLSchemað<�GomsStockRequestx�callerMethodH�pushInfinityAllocatedStockLevelx�transactionTypeH�InventoryJobð<�stockRequestEntry< productCode’�100001ð<�availableQuantity�1ð<�reservedQuantity�0ð<inventoryType’�Job_Importÿ
which seems that the whitespace and CR character are trimmed
My models are below
public class GomsStockRequest
{
[XmlAttribute("callerMethod")]
public string callerMethod { get; set; }
[XmlAttribute("transactionType")]
public string transactionType { get; set; }
public StockRequestEntry stockRequestEntry { get; set; }
}
public class StockRequestEntry
{
public string productCode { get; set; }
public int availableQuantity { get; set; }
public int reservedQuantity { get; set; }
public string inventoryType { get; set; }
}
The program is as below:
var gomsstockrequest = new GomsStockRequest()
{
callerMethod = "pushInfinityAllocatedStockLevel",
transactionType = "InventoryJob",
stockRequestEntry = new StockRequestEntry()
{
productCode = "100001",
availableQuantity = 1,
reservedQuantity = 0,
inventoryType = "Job_Import"
}
};
var serializer = new XmlSerializer(typeof(GomsStockRequest));
XmlWriter fwriter = XmlWriter.Create(new FIWriter("fiGomsStockRequest.xml"));
serializer.Serialize(fwriter, gomsstockrequest);
Does anyone have experience in this encoding?
When I view the data in Notepad++, the difference is as in screenshot
Please advise. Thank you