R
reeya
Hello all.
I am writing some "CART" data into an xml and it is not coming in the
right format. I have an dataset which has an orderID element and a
product element. The product element has a productid element.
Now once i get the cart, i take this data and using the dataset, i
write it into an xml file.
the format it "should appear" in is:
<OrderInformation>
<Order>
<Id>0</Id>
<Product>
<ProductId>21</ProductId>
</Product>
<Product>
<ProductId>22</ProductId>
</Product>
</Order>
</OrderInformation>
but its coming as
<OrderInformation>
<Order>
<Id>0</Id>
</Order>
<Product>
<ProductId>21</ProductId>
</Product>
<Product>
<ProductId>22</ProductId>
</Product>
</OrderInformation>
obviously i am adding it in an incorrect order ..
my code is:
string fileLocation =
(string)ConfigurationSettings.AppSettings["ShoppingCart.Location"];
ShoppingCart shoppingCart = new ShoppingCart();
ShoppingCart.ProductRow productRow = null;
int noOfItems = 0;
if (cart != null)
{
CartLineItem[] cLineItems = cart.CartLineItemArray;
if (cLineItems != null)
{
foreach(CartLineItem lineItem in cLineItems)
{
shoppingCart.DataSetName =
"OrderInformation"; shoppingCart.Order.AddOrderRow(noOfItems.ToString());
productRow = shoppingCart.Product.NewProductRow();
productRow.ProductID = lineItem.ProductID;
shoppingCart.Product.AddProductRow(productRow); noOfItems++;
}
if (shoppingCart.Order.Rows.Count > 0)
{
shoppingCart.WriteXml(fileLocation);
}
}
}
Can anyone please advise, what am i doing wrong here..
Thanx very much.
Reeya
I am writing some "CART" data into an xml and it is not coming in the
right format. I have an dataset which has an orderID element and a
product element. The product element has a productid element.
Now once i get the cart, i take this data and using the dataset, i
write it into an xml file.
the format it "should appear" in is:
<OrderInformation>
<Order>
<Id>0</Id>
<Product>
<ProductId>21</ProductId>
</Product>
<Product>
<ProductId>22</ProductId>
</Product>
</Order>
</OrderInformation>
but its coming as
<OrderInformation>
<Order>
<Id>0</Id>
</Order>
<Product>
<ProductId>21</ProductId>
</Product>
<Product>
<ProductId>22</ProductId>
</Product>
</OrderInformation>
obviously i am adding it in an incorrect order ..
my code is:
string fileLocation =
(string)ConfigurationSettings.AppSettings["ShoppingCart.Location"];
ShoppingCart shoppingCart = new ShoppingCart();
ShoppingCart.ProductRow productRow = null;
int noOfItems = 0;
if (cart != null)
{
CartLineItem[] cLineItems = cart.CartLineItemArray;
if (cLineItems != null)
{
foreach(CartLineItem lineItem in cLineItems)
{
shoppingCart.DataSetName =
"OrderInformation"; shoppingCart.Order.AddOrderRow(noOfItems.ToString());
productRow = shoppingCart.Product.NewProductRow();
productRow.ProductID = lineItem.ProductID;
shoppingCart.Product.AddProductRow(productRow); noOfItems++;
}
if (shoppingCart.Order.Rows.Count > 0)
{
shoppingCart.WriteXml(fileLocation);
}
}
}
Can anyone please advise, what am i doing wrong here..
Thanx very much.
Reeya