/* NetRexx */ options replace format comments java crossref symbols binary import javax.xml.parsers. import javax.xml.xpath. import org.w3c.dom. import org.xml.sax. xmlStr = '' - || '' - || '
' - || ' ' - || ' Invisibility Cream' - || ' 14.50' - || ' Makes you invisible' - || ' ' - || ' ' - || ' Levitation Salve' - || ' 23.99' - || ' Levitate yourself for up to 3 hours per application' - || ' ' - || '
' - || '
' - || ' ' - || ' Blork and Freen Instameal' - || ' 4.95' - || ' A tasty meal in a tablet; just add water' - || ' ' - || ' ' - || ' Grob winglets' - || ' 3.56' - || ' Tender winglets of Grob. Just add priwater' - || ' ' - || '
' - || '
' expr1 = '/inventory/section/item[1]' expr2 = '/inventory/section/item/price' expr3 = '/inventory/section/item/name' attr1 = 'upc' do doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(InputSource(StringReader(xmlStr))) xpath = XPathFactory.newInstance().newXPath() -- Extract attribute from 1st item element say expr1 say " "(Node xpath.evaluate(expr1, doc, XPathConstants.NODE)).getAttributes().getNamedItem(attr1) say -- Extract and display all price elments nodes = NodeList xpath.evaluate(expr2, doc, XPathConstants.NODESET) say expr2 loop i_ = 0 to nodes.getLength() - 1 say Rexx(nodes.item(i_).getTextContent()).format(10, 2) end i_ say -- Extract elements and store in an ArrayList nameList = java.util.List nameList = ArrayList() nodes = NodeList xpath.evaluate(expr3, doc, XPathConstants.NODESET) loop i_ = 0 to nodes.getLength() - 1 nameList.add(nodes.item(i_).getTextContent()) end i_ -- display contents of ArrayList say expr3 loop n_ = 0 to nameList.size() - 1 say " "nameList.get(n_) end n_ say catch ex = Exception ex.printStackTrace() end return