happy coding. I can group and sum with linq but this is a bit different. I want to group the elements and gather them one by one. I wanna group by TaxTypeCode and collect TaxAmount values. I'm sorry it's such a long question.
My xml
<Note>
<NoteLine>
<cbc:ID>1</cbc:ID>
<Quantity unitCode="C62">1.0000</Quantity>
<TaxTotal>
<cbc:TaxAmount currencyID="USD">201.00</cbc:TaxAmount>
<TaxSubtotal>
<cbc:TaxableAmount currencyID="USD">500.00</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="USD">100.00</cbc:TaxAmount>
<cbc:Percent>25.00</cbc:Percent>
<TaxCategory>
<TaxScheme>
<cbc:TaxTypeCode>0003</cbc:TaxTypeCode>
</TaxScheme>
</TaxCategory>
</TaxSubtotal>
<TaxSubtotal>
<cbc:TaxableAmount currencyID="USD">500.00</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="USD">50.00</cbc:TaxAmount>
<cbc:Percent>10.00</cbc:Percent>
<TaxCategory>
<TaxScheme>
<cbc:TaxTypeCode>9040</cbc:TaxTypeCode>
</TaxScheme>
</TaxCategory>
</TaxSubtotal>
<TaxSubtotal>
<cbc:TaxableAmount currencyID="USD">500.00</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="USD">1.00</cbc:TaxAmount>
<cbc:Percent>1.00</cbc:Percent>
<TaxCategory>
<TaxScheme>
<cbc:TaxTypeCode>0001</cbc:TaxTypeCode>
</TaxScheme>
</TaxCategory>
</TaxSubtotal>
<TaxSubtotal>
<cbc:TaxableAmount currencyID="USD">500.00</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="USD">50.00</cbc:TaxAmount>
<cbc:Percent>10.00</cbc:Percent>
<TaxCategory>
<TaxScheme>
<cbc:TaxTypeCode>8001</cbc:TaxTypeCode>
</TaxScheme>
</TaxCategory>
</TaxSubtotal>
</TaxTotal>
</NoteLine>
<NoteLine>
<cbc:ID>2</cbc:ID>
<Quantity unitCode="C62">1.0000</Quantity>
<TaxTotal>
<cbc:TaxAmount currencyID="USD">460.00</cbc:TaxAmount>
<TaxSubtotal>
<cbc:TaxableAmount currencyID="USD">1000.00</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="USD">200.00</cbc:TaxAmount>
<cbc:Percent>20.00</cbc:Percent>
<TaxCategory>
<TaxScheme>
<cbc:TaxTypeCode>0003</cbc:TaxTypeCode>
</TaxScheme>
</TaxCategory>
</TaxSubtotal>
<TaxSubtotal>
<cbc:TaxableAmount currencyID="USD">1000.00</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="USD">100.00</cbc:TaxAmount>
<cbc:Percent>10.00</cbc:Percent>
<TaxCategory>
<TaxScheme>
<cbc:TaxTypeCode>9040</cbc:TaxTypeCode>
</TaxScheme>
</TaxCategory>
</TaxSubtotal>
<TaxSubtotal>
<cbc:TaxableAmount currencyID="USD">1000.00</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="USD">100.00</cbc:TaxAmount>
<cbc:Percent>10.00</cbc:Percent>
<TaxCategory>
<TaxScheme>
<cbc:TaxTypeCode>8001</cbc:TaxTypeCode>
</TaxScheme>
</TaxCategory>
</TaxSubtotal>
<TaxSubtotal>
<cbc:TaxableAmount currencyID="USD">600.00</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="USD">60.00</cbc:TaxAmount>
<cbc:Percent>10.00</cbc:Percent>
<TaxCategory>
<TaxScheme>
<cbc:TaxTypeCode>8001</cbc:TaxTypeCode>
</TaxScheme>
</TaxCategory>
</TaxSubtotal>
</TaxTotal>
</NoteLine>
</Note>
Then we need something like this. Totals taxamount, taxableamount, taxamount. I think this is possible, but how can I do it?
The result I want
<TaxTotal>
<TaxAmount currencyID="USD">661.00</TaxAmount>
<TaxSubtotal>
<TaxableAmount currencyID="USD">1500.00</TaxableAmount>
<TaxAmount currencyID="USD">300.00</TaxAmount>
<Percent>25.00</Percent>
<TaxCategory>
<TaxScheme>
<TaxTypeCode>0003</TaxTypeCode>
</TaxScheme>
</TaxCategory>
</TaxSubtotal>
...
...
...
...
</TaxTotal>
I have a create sample class for serialize xml.
using (StreamReader reader = new StreamReader(@"C:\Users\test.xml"))
{
XmlSerializer serializer = new XmlSerializer(typeof(Note));
Note obj = (Note)serializer.Deserialize(reader);
}
But I can't do it still.