J
Joe McIntier
I am trying to sum the amounts attributes of a transaction element but
only for transaction elements where the SaleType attribute is equal to
SALE
XML Snippet:
<Root>
<Transaction Amount="1.23" SaleType="SALE">
<OptionalElelment/>
</Transaction>
<Transaction Amount="2.23" SaleType="SALE">
<OptionalElelment/>
</Transaction>
<Transaction Amount="3.23" SaleType="RETURN">
<OptionalElelment/>
</Transaction>
<Transaction Amount="4.23" SaleType="SALE">
<OptionalElelment/>
</Transaction>
</Root>
CODE Snippet:
//TRANS_TYPE_SALE is a constant = "SALE"
// Calculate the total of the SALE orders.
//<Transaction TransactionId="2" TransactionType="SALE"
// Amount="36.46">
XPathNavigator navSales = xDoc.CreateNavigator();
string xPathString = "sum(/Root/Transaction[@Transaction Type=" +
TRANS_TYPE_SALE.ToUpper() + "]/@Amount)";
XPathExpression exprSales = navSales.Compile( xPathString );
double totalAmount = (double) navSales.Evaluate(exprSales);
// Calculate the total of the RETURN orders.
//<Transaction TransactionId="2" TransactionType="RETURN"
// Amount="36.46">
XPathNavigator navReturns = xDoc.CreateNavigator();
XPathExpression exprReturns = navReturns.Compile (
"sum(/Root/Transaction/@Amount)");
double returnAmount = (double) navReturn.Evaluate(exprReturns);
The returnAmount is equal to all the Amoutns added up (expected but
not desired).
The totalAMount is equal to 0 (not expected and not desired).
I have tried many many combinations for the exprSales but have not
found the right combination that will let me sum the amounts when the
saletype = "SALES". I am quite sure that this is a simple querry but
i just cannot see the forest for the trees right now.
Any help is appreciated.
only for transaction elements where the SaleType attribute is equal to
SALE
XML Snippet:
<Root>
<Transaction Amount="1.23" SaleType="SALE">
<OptionalElelment/>
</Transaction>
<Transaction Amount="2.23" SaleType="SALE">
<OptionalElelment/>
</Transaction>
<Transaction Amount="3.23" SaleType="RETURN">
<OptionalElelment/>
</Transaction>
<Transaction Amount="4.23" SaleType="SALE">
<OptionalElelment/>
</Transaction>
</Root>
CODE Snippet:
//TRANS_TYPE_SALE is a constant = "SALE"
// Calculate the total of the SALE orders.
//<Transaction TransactionId="2" TransactionType="SALE"
// Amount="36.46">
XPathNavigator navSales = xDoc.CreateNavigator();
string xPathString = "sum(/Root/Transaction[@Transaction Type=" +
TRANS_TYPE_SALE.ToUpper() + "]/@Amount)";
XPathExpression exprSales = navSales.Compile( xPathString );
double totalAmount = (double) navSales.Evaluate(exprSales);
// Calculate the total of the RETURN orders.
//<Transaction TransactionId="2" TransactionType="RETURN"
// Amount="36.46">
XPathNavigator navReturns = xDoc.CreateNavigator();
XPathExpression exprReturns = navReturns.Compile (
"sum(/Root/Transaction/@Amount)");
double returnAmount = (double) navReturn.Evaluate(exprReturns);
The returnAmount is equal to all the Amoutns added up (expected but
not desired).
The totalAMount is equal to 0 (not expected and not desired).
I have tried many many combinations for the exprSales but have not
found the right combination that will let me sum the amounts when the
saletype = "SALES". I am quite sure that this is a simple querry but
i just cannot see the forest for the trees right now.
Any help is appreciated.