HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Working With Dynamic XML Documents, by Jon Siegel"
Vol. 6, Issue 5, p. 34

	





 
Listing 1

<purchase_order company="Enjay Manufacturing" 
number="01239876">
 <ship_to_address>
 <street>21 Pine 
Street</street>
 <city>Cleveland</city>
 <state>OH</state>
 <postcode>44113</postcode>
 </ship_to_address>
 <POitem_list>
 <POitem>
 
<POitem_name>bolt</POitem_name>
 
<POitem_number>BO1420</POitem_number>
 
<POitem_size>1/4X20</POitem_size>
 
<POitem_quantity>120gross</POitem_quantity>
 </POitem>
 <POitem>
 
<POitem_name>nut</POitem_name>
 
<POitem_number>NU14</POitem_number>
 
<POitem_size>1/4</POitem_size>
 
<POitem_quantity>120gross</POitem_quantity>
 </POitem>
 </POitem_list>
</purchase_order>

Listing 2 

// Modify any Bolt items quantity values to 150 gross
 // where their POitem_number is 'BO1420'
 DOMString checker = makeDOMString("BO1420");
 DOMString change = 
makeDOMString("150gross");
 // Loop over the items in our PO:
 for (int i = 0; i < elms.length(); i++)
 {
 Element poItem = 
(Element)elms.item(i);
 // ino is the POitem_number element for this 
poItem:
 NodeList ino =
 
poItem.getElementsByTagName(makeDOMString("POitem_number"));
 // iqty is the POitem_quantity element for 
this poItem:
 NodeList iqty =
 
poItem.getElementsByTagName(makeDOMString("POitem_quantity"));
 if (ino.length() != 1 || iqty.length() != 
1)
 {
 System.err.println("Invalid 
purchase Order");
 System.exit(1);
 }
 // This next line is explained in detail in 
the text
 if 
(((Text)(ino.item(0).firstChild())).data().equals(checker))
 {
 // Compare successful: this 
poItem needs its gross changed
 
((Text)(iqty.item(0).firstChild())).data(change);
 }
 }
 
Listing 3 

{
 // Retrieve a purchasing server object reference
 // from the naming service...
 PurchasingServer server = whatever;
 // Set up the document root of our PO tree 
structure:
 //
 dom.Document thePO = whatever; // set equal to our PO 
document root
 // Here we go...
 if (server.PlaceOrder(thePO)) // this line sends 
the entire document
 {
 // Success!
 }
 else
 {
 // Whoops.
 }
 }



  
 
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.