Listing 1

<?xml version=”1.0” encoding=”UTF-8”?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV=”http://schemas.xmlsoap.org/soap/envelope/”>
	<SOAP-ENV:Body>
		<po xmlns=”http://www.skatestown.com/ns/po”
			id=”50383” submitted=”2001-12-06”>
			<billTo>
			<company>The Skateboard Warehouse</company>
			<street>One Warehouse Park</street>
			<street>Building 17</street>
			<city>Boston</city>
			<state>MA</state>
			<postalCode>01775</postalCode>
		</billTo>
		<shipTo>
			<company>The Skateboard Warehouse</company>
			<street>One Warehouse Park</street>
			<street>Building 17</street>
			<city>Boston</city>
			<state>MA</state>
			<postalCode>01775</postalCode>
		</shipTo>
		<order>
			<item sku=”318-BP” quantity=”5”>
				<description>Skateboard backpack; five
				 pockets</description>
			</item>
			<item sku=”947-TI” quantity=”12”>
				<description>Street-style titanium
				 skateboard.</description>
			</item>
			<item sku=”008-PR” quantity=”1000”/>
		</order>
	</po>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Listing 2

import com.ximpleware.*;
import java.io.*;

class project{

	public void static main(String[] args){
		try{
			// application stay here
		}
		catch(IOException e){
			System.out.println(“ IO exception
			condition”+e);
		}
		catch(ParseException e){
			System.out.println(“ XML file parsing error
			\n”+e);
		}
		catch(NavException e){
			System.out.println(
				“ Exception during navigation “+e);
		}
	}
}

Listing 3

// parse SOAP message named po.xml from the diskFile
	f = new File(“po.xml”);
FileInputStream fis = new FileInputStream(f);

// find out file length and allocate buffer
byte[] b = new byte[(int) f.length()];

// read file content into the buffer
fis.read(b);

//create an instance of VTDGen
VTDGen vg = new VTDGen();

// assign the buffer to VTDGen
vg.setDoc(b);

// parse with namespace awareness turned off
vg.parse(true);

Listing 4

// get VTDNav
VTDNav vn = vg.getNav();

// the cursor initially at root
if (vn.toElementNS(VTDNav.FIRST_CHILD,
	“http://schemas.xmlsoap.org/soap/envelope/”,
	“Body”))
{
	if (vn.toElementNS(VTDNav.FIRST_CHILD,
	“http://www.skatestown.com/ns/po”,
	“po”))
{
	// print of the attribate value of “id”
	int id = vn.getAttrVal(“id”);
	if (id !=-1)
System.out.println(“id value: “+vn.toString(id));
// print out the element element fragment for
	billTo
// getElementFragment returns a long val
// upper 32 bits are length
// lower 32 bits are offset
if(vn.toElement(VTDNav.FIRST_CHILD, “billTo”))
{
	long l = vn.getElementFragment();
	int len = (int) (l>>32);
	int offset = (int)l;
	System.out.print(“element fragment for billTo
		==> \n”);
	System.out.println(new String(
		b,offset, len));
}
// print out the element element fragment for
shipTo
if(vn.toElement(VTDNav.NEXT_SIBLING, “shipTo”))
{
	long l = vn.getElementFragment();
	int len = (int) (l>>32);
	int offset = (int)l;
	System.out.print(“element fragment for shipTo
		==> \n”);
	System.out.println(new String(
		b,offset, len));
}
// navigate across all elements of order
// print out various attributes and text content
// using getAttrVal, getText, toString
// those functions return -1 if no value should
	be returned,
// corresponding to null in DOM.
if(vn.toElement(VTDNav.NEXT_SIBLING, “order”))
{
	if (vn.toElement(VTDNav.FIRST_CHILD,”item”)){
		do {
			int temp = vn.getAttrVal(“sku”);

			temp = vn.getAttrVal(“quantity”);
			if (temp!=-1)
				System.out.println(“quantity ==>”
					+vn.toString(temp));
			if (vn.toElement(VTDNav.FIRST_CHILD,
				“description”))
			{
				temp = vn.getText();
				if (temp!=-1)
					System.out.println(“ text for
						description ==> “
					+vn.toString(temp));
			vn.toElement(VTDNav.PARENT);
		}
	} while(vn.toElement(VTDNav.NEXT_
		SIBLING,”item”));
				}
			}
		}

	}

Listing 5

<?xml version=”1.0” encoding=”UTF-8”?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV=”http://schemas.xmlsoap.org/soap/envelope/”>
	<SOAP-ENV:Body>
		<invoice xmlns=”http://www.skatestown.com/ns/po”
		  id=”50383” submitted=”2001-12-06”>
		<billTo>
			<company>The Skateboard Warehouse</company>
			<street>One Warehouse Park</street>
			<street>Building 17</street>
			<city>Boston</city>
			<state>MA</state>
			<postalCode>01775</postalCode>
		</billTo>
		<shipTo>
			<company>The Skateboard Warehouse</company>
			<street>One Warehouse Park</street>
			<street>Building 17</street>
			<city>Boston</city>
			<state>MA</state>
		<postalCode>01775</postalCode>
		</shipTo>
		<order>
			<item sku=”318-BP” quantity=”5” price=”30.00”>
				<description>Skateboard backpack; five
				  pockets</description>
			</item>
			<item sku=”947-TI” quantity=”12” price=”40.00”>
				<description>Street-style titanium
				  skateboard.</description>
			</item>
			<item sku=”008-PR” quantity=”1000” price=”5.00”>/>
			</order>
		<status> shipped </status>
		<total> 5630.00 </total>
	</invoice>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Listing 6

// compose invoice
// first set the cursor to root
// then navigates to po and get the fragment offset and
	length using getElementFragment
// output writes to invoice.xml;
FileOutputStream fos = new FileOutputStream
	(new File(“invoice.xml”));
fos.write(
“<SOAP-ENV:Envelope xmlns:SOAP-ENV=\”http://schemas.xmlsoap.
org/soap/envelope/\”>\n<SOAP-ENV:Body><invoice”.getBytes());
vn.toElement(VTDNav.ROOT);
vn.toElementNS(VTDNav.FIRST_CHILD,
“http://schemas.xmlsoap.org/soap/envelope/”,
“Body”);
vn.toElementNS(VTDNav.FIRST_CHILD,
“http://www.skatestown.com/ns/po”,
“po”);
long l = vn.getElementFragment(); // get the offset and
	length of the fragment
int offset = (int) l +3;
int len = (int)(l>>32);
vn.toElement(VTDNav.FIRST_CHILD,”order”);
long l2 = vn.getElementFragment();
int offset2 = (int)l2;
int len2 = (int)(l2>>32);
vn.toElement(VTDNav.FIRST_CHILD,”item”);
do{
int temp = vn.getAttrVal(“quantity”);
int ot = vn.getTokenOffset(temp)+vn.getTokenLength(temp)+1;
fos.write(b, offset, ot-offset);
if (vn.matchTokenString(vn.getAttrVal(“sku”),”318-BP”))
fos.write(“ price=\”30.00\””.getBytes());
if (vn.matchTokenString(vn.getAttrVal(“sku”),”947-TI”))
fos.write(“ price=\”40.00\””.getBytes());
if (vn.matchTokenString(vn.getAttrVal(“sku”),”008-PR”))
fos.write(“ price=\”5.00\””.getBytes());
offset = ot;
}while(vn.toElement(VTDNav.NEXT_SIBLING,”item”));
fos.write(b,offset, offset2+len2-offset);
fos.write(“<status>shipped</status>\n<total>5630.00</total>\
n”.getBytes());
fos.write(“</invoice>\n</SOAP-ENV:Body>\n</SOAP-ENV:
Envelope>”.getBytes());