Howdy, I’ve confronted an issue about making a go struct that when unmarshalled can match the under xml construction. The issue is in PAYMENTS
half. Say cost struct has a discipline named PMTTYPE
and PMTAMOUNT
how are you going to unmarshal an inventory of PAYMENTS and have them nested like under with out making a nested construction.
<TOTALS>
<TOTALTAXEXCL>169.49</TOTALTAXEXCL>
<!-- Whole of all of the gadgets unique of Tax-->
<TOTALTAXINCL>200</TOTALTAXINCL>
<!-- Whole of all of the gadgets inclusive of Tax-->
<DISCOUNT>0.00</DISCOUNT>
</TOTALS>
<PAYMENTS>
<PMTTYPE>CASH</PMTTYPE>
<!-- Mode of Cost can both be CASH, CHEQUE, EMONEY or CCARD if receipt is generated. On this case cost is already received-->
<PMTAMOUNT>200.00</PMTAMOUNT>
<!-- Cost amount-->
<PMTTYPE>INVOICE</PMTTYPE>
<!-- Mode of Cost can solely be INVOICE if bill is generated. On this case cost is just not but obtained that's the reason we use Bill -->
<PMTAMOUNT>200.00</PMTAMOUNT>
<!-- Cost amount-->
</PAYMENTS>
<VATTOTALS>
<VATRATE>A</VATRATE>
<!-- Tax group relevant on the gadgets for VAT gadgets ought to A and for no VAT gadgets ought to be C-->
<NETTAMOUNT>169.49</NETTAMOUNT>
<!-- Whole of all of the gadgets unique of Tax-->
<TAXAMOUNT>30.51</TAXAMOUNT>
<!-- Tax quantity paid-->
</VATTOTALS>
You imply like this? Go Playground – The Go Programming Language
Thanks for that makes an attempt. I meant turning a go struct into XML just like the one above. The expectation is having PMTTYPE adopted by PMTAMOUNT then PMTTYPE adopted by PMTAMOUNT as an inventory
Ah, I see. Going from code to an encoding (e.g. to XML or to JSON, and many others.) known as “marshaling.” Unmarshaling is while you convert from XML (or JSON, and many others.) to structs (or no matter different knowledge sort you might be deserializing from).
If you need the code that may produce that XML, I believe you need this:
When you have fields different than simply two (PMTTYPE
and PMTAMOUNT
), I may need a special thought, however I believe that is essentially the most easy for simply these two varieties.
This matter was mechanically closed 90 days after the final reply. New replies are now not allowed.