I started really working with DOM and XPath a couple of weeks ago. I wrote some classes that allow me to pass in an xml document and an element name (...as a
String) and have it generate the xpath location for me. I've done this for elements and attributes, but I'd like to add another feature. I'd like to insert "[?]" after every repeating node.
For example lets say we have...
<?xml version="1.0" encoding="UTF-8"?>
<PurchaseOrder orderDate="Oct 30, 2000">
<ShipTo city="San Jose" name="Fox Mulder" state="California" street="47 Rosedale Drive" zip="56789"></ShipTo>
<Contact contactEmail="bobsmith@ca.ibm.com" contactName="Bob Smith" contactPhone="416-448-4414"></Contact>
<Items>
<Item>
<ProductName>TShirts</ProductName>
<quantity>50</quantity>
<price>20</price>
<SubItem>
<orderno>9876</orderno>
<desc>Sub Item A</desc>
</SubItem>
</Item>
<Item>
<ProductName>Tennis balls</ProductName>
<quantity>500</quantity>
<price>3</price>
<SubItem>
<orderno>12341</orderno>
<desc>Sub Item One</desc>
</SubItem>
<SubItem>
<orderno>12342</orderno>
<desc>Sub Item Two</desc>
</SubItem>
<SubItem>
<orderno>12343</orderno>
<desc>Sub Item Three</desc>
</SubItem>
</Item>
</Items>
</PurchaseOrder>
Right now if I ask it to give me the location path for "quantity", it returns...
/PurchaseOrder/Items/Item/quantity
....which is correct, but what I'd like to do is have it send back
/PurchaseOrder/Items/Item[?]/quantity
Any ideas how you can idenfity nodes like "Item" that begin a repeating structure?
Regards,
Byron