XML Attributes |
|
// This is the main project file for VC++ application project // generated using an Application Wizard. #include "stdafx.h" #using <mscorlib.dll> using namespace std; using namespace System; __value struct CEmployeeRecord { String *Username; String *Password; Double Salary; __wchar_t MaritalStatus; }; int _tmain() { // TODO: Please replace the sample code below with your own. CEmployeeRecord emplRecord; emplRecord.Username = S"kallar"; emplRecord.Password = S"7hd47D89"; emplRecord.Salary = 20.12; emplRecord.MaritalStatus = L'D'; Console::WriteLine(S"Username: {0}", emplRecord.Username); Console::WriteLine(S"Password: {0}", emplRecord.Password); Console::WriteLine(S"Marital Status: {0}", __box(emplRecord.MaritalStatus)); Console::WriteLine(S"Hourly Salary: {0}", __box(emplRecord.Salary)); Console::WriteLine(); return 0; } This would produce: Username: kallar Password: 7hd47D89 Marital Status: D Hourly Salary: 20.12 Press any key to continue The members of such a class are said to describe the class. When you instantiate the class (when you declare a variable of that class), you can provide value for one or more member variables. Another instance of the class can have different values. In XML, a tag is like a variable of a C++ class, except that you don't have to create the class but you must create the tag. Inside of the start tag, you can provide one or more attributes that mimic the member variables of a class. An attribute is created in the start tag using the formula: <tag Attribute_Name="Value">Element_Value</tag> Like the tag, the name of an attribute is up to you. On the right side of the attribute, type its value in double-quotes. The end tag doesn't need any information about any attribute. It is only used to close the tag. Here is an example of a tag that uses an attribute: <salary status="Full Time">22.05</salary > In this example, status="Full Time" is called an attribute of the salary element. One of the good features of an attribute is that it can carry the same type of value as that of an XML tag. Therefore, using an attribute, you can omit giving a value to a tag. For example, instead of creating the following tag with its value: <movie>Coming to America</movie> You can use an attribute to carry the value of the tag. Here is an example: <movie title="Coming to America"></movie> In this case, you can still provide another or new value for the tag. You can create more than one attribute in a tag. To do this, separate them with an empty space. Here is an example: <movie title="Coming to America" director="John Landis" length="116 min">Nile Rodgers</movie> If you create a tag that uniquely contains attributes without a formal value, you can omit the end tag. In this case, you can close the start tag as you would do for an empty tag. Here is an example: <movie title="Coming to America" /> |
Practical Learning: Creating XML Attributes |
<?xml version="1.0" encoding="utf-8"?> <StoreItems> <Item ItemNumber="947783" ItemDescription="Double-faced wool coat" UnitPrice="275.25" /> <Item ItemNumber="934687" ItemDescription="Floral Silk Tank Blouse" UnitPrice="180.00" /> <Item ItemNumber="973947" ItemDescription="Push Up Bra" UnitPrice="50.00" /> <Item ItemNumber="987598" ItemDescription="Chiffon Blouse" UnitPrice="265.00" /> <Item ItemNumber="974937" ItemDescription="Bow Belt Skirtsuit" UnitPrice="245.55" /> <Item ItemNumber="743765" ItemDescription="Cable-knit Sweater" UnitPrice="45.55" /> <Item ItemNumber="747635" ItemDescription="Jeans with Heart Belt" UnitPrice="25.65" /> <Item ItemNumber="765473" ItemDescription="Fashionable mini skirt" UnitPrice="34.55" /> <Item ItemNumber="754026" ItemDescription="Double Dry Pants" UnitPrice="28.55" /> <Item ItemNumber="730302" ItemDescription="Romantic Flower Dress" UnitPrice="24.95" /> <Item ItemNumber="209579" ItemDescription="Cotton Polo Shirt" UnitPrice="45.75" /> <Item ItemNumber="267583" ItemDescription="Pure Wool Cap" UnitPrice="25.00" /> <Item ItemNumber="248937" ItemDescription="Striped Cotton Shirt" UnitPrice="65.55" /> <Item ItemNumber="276057" ItemDescription="Two-Toned Ribbed Crewneck" UnitPrice="9.75" /> <Item ItemNumber="267945" ItemDescription="Chestnut Italian Shoes" UnitPrice="165.75" /> <Item ItemNumber="409579" ItemDescription="Under Collar and Placket Jacket" UnitPrice="265.15" /> <Item ItemNumber="467583" ItemDescription="Country Coat Rugged Wear" UnitPrice="35.55" /> <Item ItemNumber="448937" ItemDescription="Carpenter Jeans" UnitPrice="24.95" /> <Item ItemNumber="476057" ItemDescription="Double-Cushion Tennis Shoes" UnitPrice="48.75" /> <Item ItemNumber="467945" ItemDescription="Stitched Center-Bar Belt" UnitPrice="32.50" /> </StoreItems> |
|
private: System::Void btnLoad_Click(System::Object * sender, System::EventArgs * e) { this->dataSet1->ReadXml(S"Inventory.xml"); this->dataGrid1->DataSource = this->dataSet1; this->dataGrid1->DataMember = S"Item"; } |
private: System::Void btnClose_Click(System::Object * sender, System::EventArgs * e) { Close(); } |
#pragma once #include "Inventory.h" namespace DepartmentStore1 { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; . . . No Change private: System::Void btnInventory_Click(System::Object * sender, System::EventArgs * e) { Inventory *frm = new Inventory; frm->ShowDialog(); } }; } |
|
private: System::Void txtPartID1_Leave(System::Object * sender, System::EventArgs * e) { String *partNo = this->txtPartID1->Text; String *partID = 0; XmlTextReader *xtr = new XmlTextReader(S"Inventory.xml"); while(xtr->Read()) { switch(xtr->NodeType) { case XmlNodeType::Element: partID = xtr->GetAttribute(S"ItemNumber"); if( partNo->Equals(partID) ) { this->txtDecription1->Text = xtr->GetAttribute(S"ItemDescription"); this->txtUnitPrice1->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity1->Text = S"1"; this->txtSubTotal1->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity1->Focus(); } break; } } } private: System::Void txtPartID2_Leave(System::Object * sender, System::EventArgs * e) { String *partNo = this->txtPartID2->Text; String *partID = 0; XmlTextReader *xtr = new XmlTextReader(S"Inventory.xml"); while(xtr->Read()) { switch(xtr->NodeType) { case XmlNodeType::Element: partID = xtr->GetAttribute(S"ItemNumber"); if( partNo->Equals(partID) ) { this->txtDescription2->Text = xtr->GetAttribute(S"ItemDescription"); this->txtUnitPrice2->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity2->Text = S"1"; this->txtSubTotal2->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity2->Focus(); } break; } } } private: System::Void txtPartID3_Leave(System::Object * sender, System::EventArgs * e) { String *partNo = this->txtPartID3->Text; String *partID = 0; XmlTextReader *xtr = new XmlTextReader(S"Inventory.xml"); while(xtr->Read()) { switch(xtr->NodeType) { case XmlNodeType::Element: partID = xtr->GetAttribute(S"ItemNumber"); if( partNo->Equals(partID) ) { this->txtDescription3->Text = xtr->GetAttribute(S"ItemDescription"); this->txtUnitPrice3->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity3->Text = S"1"; this->txtSubTotal3->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity3->Focus(); } break; } } } private: System::Void txtPartID4_Leave(System::Object * sender, System::EventArgs * e) { String *partNo = this->txtPartID4->Text; String *partID = 0; XmlTextReader *xtr = new XmlTextReader(S"Inventory.xml"); while(xtr->Read()) { switch(xtr->NodeType) { case XmlNodeType::Element: partID = xtr->GetAttribute(S"ItemNumber"); if( partNo->Equals(partID) ) { this->txtDescription4->Text = xtr->GetAttribute(S"ItemDescription"); this->txtUnitPrice4->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity4->Text = S"1"; this->txtSubTotal4->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity4->Focus(); } break; } } } private: System::Void txtPartID5_Leave(System::Object * sender, System::EventArgs * e) { String *partNo = this->txtPartID5->Text; String *partID = 0; XmlTextReader *xtr = new XmlTextReader(S"Inventory.xml"); while(xtr->Read()) { switch(xtr->NodeType) { case XmlNodeType::Element: partID = xtr->GetAttribute(S"ItemNumber"); if( partNo->Equals(partID) ) { this->txtDescription5->Text = xtr->GetAttribute(S"ItemDescription"); this->txtUnitPrice5->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity5->Text = S"1"; this->txtSubTotal5->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity5->Focus(); } break; } } } private: System::Void txtPartID6_Leave(System::Object * sender, System::EventArgs * e) { String *partNo = this->txtPartID6->Text; String *partID = 0; XmlTextReader *xtr = new XmlTextReader(S"Inventory.xml"); while(xtr->Read()) { switch(xtr->NodeType) { case XmlNodeType::Element: partID = xtr->GetAttribute(S"ItemNumber"); if( partNo->Equals(partID) ) { this->txtDescription6->Text = xtr->GetAttribute(S"ItemDescription"); this->txtUnitPrice6->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity6->Text = S"1"; this->txtSubTotal6->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity6->Focus(); } break; } } } private: System::Void txtPartID7_Leave(System::Object * sender, System::EventArgs * e) { String *partNo = this->txtPartID7->Text; String *partID = 0; XmlTextReader *xtr = new XmlTextReader(S"Inventory.xml"); while(xtr->Read()) { switch(xtr->NodeType) { case XmlNodeType::Element: partID = xtr->GetAttribute(S"ItemNumber"); if( partNo->Equals(partID) ) { this->txtDescription7->Text = xtr->GetAttribute(S"ItemDescription"); this->txtUnitPrice7->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity7->Text = S"1"; this->txtSubTotal7->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity7->Focus(); } break; } } } private: System::Void txtPartID8_Leave(System::Object * sender, System::EventArgs * e) { String *partNo = this->txtPartID8->Text; String *partID = 0; XmlTextReader *xtr = new XmlTextReader(S"Inventory.xml"); while(xtr->Read()) { switch(xtr->NodeType) { case XmlNodeType::Element: partID = xtr->GetAttribute(S"ItemNumber"); if( partNo->Equals(partID) ) { this->txtDescription8->Text = xtr->GetAttribute(S"ItemDescription"); this->txtUnitPrice8->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity8->Text = S"1"; this->txtSubTotal8->Text = xtr->GetAttribute(S"UnitPrice"); this->txtQuantity8->Focus(); } break; } } } |
void CalculateTotal(void) { double subTotal1 = this->txtSubTotal1->Text->ToDouble(0); double subTotal2 = this->txtSubTotal2->Text->ToDouble(0); double subTotal3 = this->txtSubTotal3->Text->ToDouble(0); double subTotal4 = this->txtSubTotal4->Text->ToDouble(0); double subTotal5 = this->txtSubTotal5->Text->ToDouble(0); double subTotal6 = this->txtSubTotal6->Text->ToDouble(0); double subTotal7 = this->txtSubTotal7->Text->ToDouble(0); double subTotal8 = this->txtSubTotal8->Text->ToDouble(0); double totalOrder = subTotal1 + subTotal2 + subTotal3 + subTotal4 + subTotal5 + subTotal6 + subTotal7 + subTotal8; this->txtTotalOrder->Text = totalOrder.ToString(S"F"); } |
private: System::Void txtQuantity1_Leave(System::Object * sender, System::EventArgs * e) { double unitPrice = this->txtUnitPrice1->Text->ToDouble(0); int qty = this->txtQuantity1->Text->ToInt16(0); double subTotal = unitPrice * qty; this->txtSubTotal1->Text = subTotal.ToString(S"F"); CalculateTotal(); } private: System::Void txtQuantity2_Leave(System::Object * sender, System::EventArgs * e) { double unitPrice = this->txtUnitPrice2->Text->ToDouble(0); int qty = this->txtQuantity2->Text->ToInt16(0); double subTotal = unitPrice * qty; this->txtSubTotal2->Text = subTotal.ToString(S"F"); CalculateTotal(); } private: System::Void txtQuantity3_Leave(System::Object * sender, System::EventArgs * e) { double unitPrice = this->txtUnitPrice3->Text->ToDouble(0); int qty = this->txtQuantity3->Text->ToInt16(0); double subTotal = unitPrice * qty; this->txtSubTotal3->Text = subTotal.ToString(S"F"); CalculateTotal(); } private: System::Void txtQuantity4_Leave(System::Object * sender, System::EventArgs * e) { double unitPrice = this->txtUnitPrice4->Text->ToDouble(0); int qty = this->txtQuantity4->Text->ToInt16(0); double subTotal = unitPrice * qty; this->txtSubTotal4->Text = subTotal.ToString(S"F"); CalculateTotal(); } private: System::Void txtQuantity5_Leave(System::Object * sender, System::EventArgs * e) { double unitPrice = this->txtUnitPrice5->Text->ToDouble(0); int qty = this->txtQuantity5->Text->ToInt16(0); double subTotal = unitPrice * qty; this->txtSubTotal5->Text = subTotal.ToString(S"F"); CalculateTotal(); } private: System::Void txtQuantity6_Leave(System::Object * sender, System::EventArgs * e) { double unitPrice = this->txtUnitPrice6->Text->ToDouble(0); int qty = this->txtQuantity6->Text->ToInt16(0); double subTotal = unitPrice * qty; this->txtSubTotal6->Text = subTotal.ToString(S"F"); CalculateTotal(); } private: System::Void txtQuantity7_Leave(System::Object * sender, System::EventArgs * e) { double unitPrice = this->txtUnitPrice7->Text->ToDouble(0); int qty = this->txtQuantity7->Text->ToInt16(0); double subTotal = unitPrice * qty; this->txtSubTotal7->Text = subTotal.ToString(S"F"); CalculateTotal(); } private: System::Void txtQuantity8_Leave(System::Object * sender, System::EventArgs * e) { double unitPrice = this->txtUnitPrice8->Text->ToDouble(0); int qty = this->txtQuantity8->Text->ToInt16(0); double subTotal = unitPrice * qty; this->txtSubTotal8->Text = subTotal.ToString(S"F"); CalculateTotal(); } |
private: System::Void button2_Click(System::Object * sender, System::EventArgs * e) { Close(); } |
#pragma once #include "Inventory.h" #include "OrderProcessing.h" namespace DepartmentStore1 { . . . No Change private: System::Void btnOrders_Click(System::Object * sender, System::EventArgs * e) { OrderProcessing *frm = new OrderProcessing; frm->ShowDialog(); } }; } |
private: System::Void btnClose_Click(System::Object * sender, System::EventArgs * e) { Close(); } |
|
||
Home | Copyright © 2004-2010 FunctionX, Inc. | |
|