7.2. The Worldwide Widget expense report Figure 7-1 shows the Worldwide Widget Corporation expense report.[1] [1] You can find the worksheets used in this chapter among the book's example files. Figure 7-1. The expense worksheet (expenses.xls) Excel, like the other Office products, has no restricted list of "supported XML vocabularies". Accordingly, Worldwide has developed its own vocabulary for expense reporting. The XML representation of a report is shown in Example 7-1. Example 7-1. Expense report in XML (expenses.xml) <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <expenseReport xmlns="http://xmlinoffice.com/expenses" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlinoffice.com/expenses expenses.xsd"> <empName>Ellen Sandler</empName> <empNum>305</empNum> <purpose>Sales meeting with ABC Corp.</purpose> <deptCode>305</deptCode> <billToCode>1104</billToCode> <periodFrom>2004-04-16</periodFrom> <periodTo>2004-04-18</periodTo> <expense> <date>2004-04-16</date> <explanation>Phone call from the hotel</explanation> <phone>.75</phone> </expense> <!-- ... --> <expense> <date>2004-04-16</date> <explanation>Dry Cleaning</explanation> <other> <code>883</code> <amount>16.75</amount> </other> </expense> </expenseReport> The report conforms to the schema shown in Example 7-2. As we'll see in 7.5.2, "Inferring a schema", on page 150, Excel doesn't require a schema, but Worldwide has one as part of its comprehensive XML-based information management plan. Example 7-2. Expense report schema (expenses.xsd) <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <xs:schema targetNamespace="http://xmlinoffice.com/expenses" xmlns="http://xmlinoffice.com/expenses" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="expenseReport" type="ExpenseReportType"/> <xs:complexType name="ExpenseReportType"> <xs:sequence> <xs:element name="empName" type="xs:string"/> <xs:element name="empNum" type="xs:integer"/> <xs:element name="purpose" type="xs:string"/> <xs:element name="deptCode" type="xs:integer"/> <xs:element name="billToCode" type="xs:integer"/> <xs:element name="periodFrom" type="xs:date"/> <xs:element name="periodTo" type="xs:date"/> <xs:element name="expense" type="ExpenseType" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="ExpenseType"> <xs:sequence> <xs:element name="date" type="xs:date"/> <xs:element name="explanation" type="xs:string"/> <xs:element name="mileage" type="xs:integer" minOccurs="0"/> <xs:element name="airFare" type="xs:decimal" minOccurs="0"/> <xs:element name="perDiem" type="xs:decimal" minOccurs="0"/> <xs:element name="lodging" type="xs:decimal" minOccurs="0"/> <xs:element name="auto" type="xs:decimal" minOccurs="0"/> <xs:element name="taxi" type="xs:decimal" minOccurs="0"/> <xs:element name="phone" type="xs:decimal" minOccurs="0"/> <xs:element name="businessMeals" type="xs:decimal" minOccurs="0"/> <xs:element name="other" type="OtherExpenseType" minOccurs="0"/> </xs:sequence> </xs:complexType> <xs:complexType name="OtherExpenseType"> <xs:sequence> <xs:element name="code" type="xs:integer"/> <xs:element name="amount" type="xs:decimal"/> </xs:sequence> </xs:complexType> </xs:schema> |