// Purchase Order sample XML
XPathPullParser parser = new XPathPullParserImpl();
parser.setInput(SampleXml.getPurchaseOrder(), null);
// Purchase Order Node (root)
XPathElement expectedXPathElement = new SingleSlashXPathElement(
"PurchaseOrder", null);
expectedXPathElement.addPredicate("PurchaseOrderNumber", "99503");
expectedXPathElement.addPredicate("OrderDate", "1999-10-20");
assertEquals(XPathPullParser.START_TAG, parser.next());
assertEquals(expectedXPathElement, parser.getCurrentElement());
// Purchase Order "PurchaseOrderNumber" Attribute
assertAttribute(parser, expectedXPathElement, "PurchaseOrderNumber",
"99503");
// Purchase Order "OrderDate" Attribute
assertAttribute(parser, expectedXPathElement, "OrderDate", "1999-10-20");
// Address Node
expectedXPathElement = new SingleSlashXPathElement("Address",
expectedXPathElement);
expectedXPathElement.addPredicate("Type", "Shipping");
// Shipping Address
assertEquals(XPathPullParser.START_TAG, parser.next());
assertEquals(expectedXPathElement, parser.getCurrentElement());
assertAttribute(parser, expectedXPathElement, "Type", "Shipping");
assertTextElement(parser, expectedXPathElement, "Name", "Ellen Adams");
assertTextElement(parser, expectedXPathElement, "Street",
"123 Maple Street");
assertTextElement(parser, expectedXPathElement, "City", "Mill Valley");
assertTextElement(parser, expectedXPathElement, "State", "CA");
assertTextElement(parser, expectedXPathElement, "Zip", "10999");
assertTextElement(parser, expectedXPathElement, "Country", "USA");
assertEquals(XPathPullParser.END_TAG, parser.next());
assertEquals(expectedXPathElement, parser.getCurrentElement());
assertEquals(XPathPullParser.START_TAG, parser.next());
// Adding another type predicate will override the previous one
expectedXPathElement.addPredicate("Type", "Billing");
assertEquals(expectedXPathElement, parser.getCurrentElement());
// Billing Address
assertAttribute(parser, expectedXPathElement, "Type", "Billing");
assertTextElement(parser, expectedXPathElement, "Name", "Tai Yee");
assertTextElement(parser, expectedXPathElement, "Street",
"8 Oak Avenue");
assertTextElement(parser, expectedXPathElement, "City", "Old Town");
assertTextElement(parser, expectedXPathElement, "State", "PA");
assertTextElement(parser, expectedXPathElement, "Zip", "95819");
assertTextElement(parser, expectedXPathElement, "Country", "USA");
assertEquals(XPathPullParser.END_TAG, parser.next());
assertEquals(expectedXPathElement, parser.getCurrentElement());
expectedXPathElement = expectedXPathElement.getPreviousElement();
assertTextElement(parser, expectedXPathElement, "DeliveryNotes",
"Please leave packages in shed by driveway.");
}