Shopping carts are an indispensable part of the e-commerce website, but most shopping carts can only be displayed as a customer to select the product, the client cannot extract the contents of the shopping cart to meet the needs of their own transaction, and this It is necessary in some e-commerce activities. The emergence of XML makes data transmitted on the network make it meaningful, and we can display the contents of a shopping cart according to different requirements.
This article will analyze an XML-based shopping cart implemented by Java. Below is an intrinsic structure of a shopping cart containing five items: its root element is Cart, TOTAL element indicates the total amount of the shopping cart, each Item element represents a commodity, the child elements in the item indicate respectively. The specific information of this item can be added, modified or deleted depending on the actual situation.
Here, you need to create a class indicating a shopping cart: Xmlcart.java, which is a JavaBean, so it contains an empty constructor. This class contains some basic functions of the shopping cart: generate an empty shopping cart, add goods to the shopping cart, delete the goods in the shopping cart, change the number of goods in the shopping cart and empty shopping carts. It has a global private variable "private xmldocument mycart", MyCart is used to store details in the shopping cart, the basic function of the shopping cart is to operate on it, its type is XMLDocument, an XML document. In this way, the operation of the shopping cart is converted into the addition, deletion, and elements of the child elements in mycart, modification, and the like. Full text: XML-based shopping cart with Java