
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Putting Together an XML Document
|
863
The code reconstitutes the invoice and saves it as ReceivedInvoice.xml, the contents
of which are shown here:
<Invoice invoiceDate="2003-10-05" invoiceNumber="INV-01"><billInfo><name>Beerly
Standing</name><attn>Accounting</attn><street>98 North Street</street><city>Intox</
city><state>NH</state></billInfo><shipInfo><name>Beerly Standing</name><attn>
Receiving</attn><street>47 South Street</street><city>Intox</city><state>NH</state></
shipInfo><Items><item partNum="98745"><productName>Brown Eyed Stout</productName>
<quantity>12</quantity><price>23.99</price><shipDate>2003-12-20</shipDate></item>
<item partNum="34987"><productName>Diamond Pearl Lager</productName><quantity>22</
quantity><price>35.98</price><shipDate>2003-12-20</shipDate></item><item
partNum="AK254"><productName>Job Site Ale</productName><quantity>50</quantity><price>
12.56</price><shipDate>2003-11-12</shipDate></item></Items></Invoice>
Discussion
In the Solution code, the first step is to create a set of XmlDocuments for the Invoice,
BillingEnvelope, ShippingEnvelope, and FulfillmentEnvelope. Then you create the
new root
Invoice element in the invoice XmlDocument:
XmlDocument invoice = new XmlDocument( );
XmlDocument billing = new XmlDocument( );
XmlNodeList shipList = shipping.SelectNodes("/ShippingEnvelope/shipInfo"); ...