parse arg xmlFileName /* create an instance of the JAXP DocumentBuilderFactory */ factory=bsf.loadClass("javax.xml.parsers.DocumentBuilderFactory")~newInstance /* make sure that parser is set to be namespace aware */ factory~setNamespaceAware(.true) /* now create the DocumentBuilder object */ parser=factory~newDocumentBuilder /* create a Rexx object for error handling */ eh=.errorHandler~new /* create a Java proxy using the Rexx object for error handling */ javaProxy=BsfCreateRexxProxy(eh, , "org.xml.sax.ErrorHandler") /* set the parser's error handler */ parser~setErrorHandler(javaProxy) /* parse the file, result is full DOM-tree */ document=parser~parse(xmlFileName) /* get constant value to determine node types to filter */ .local~show_element=bsf.getConstant("org.w3c.dom.traversal.NodeFilter", "SHOW_ELEMENT") whatToShow=.show_element /* create a TreeWalker with only Element nodes */ walker=document~createTreeWalker(document, whatToShow, .nil, .true) /* process list of Element nodes */ call walkTheTree walker~firstChild, 0 ::requires BSF.CLS /* get the Java support */ ::routine walkTheTree use arg node, level -- say "09"x~copies(level) || pp(node~getNodeName) number_p = 0 child=node~firstChild /* depth first */ do while child<>.nil if child~getNodeName == "p" then number_p = number_p + 1 call walkTheTree child, level+1 /* one level deeper */ child=child~nextSibling /* breadth next */ end if number_p >0 then say "In diesem File sind "number_p "Paragraphen !!" ::class ErrorHandler /* will handle "org.xml.sax.ErrorHandler" events*/ ::method unknown /* handles "warning", "error" and "fatalError" events */ use arg methName, argArray /* fetch arguments */ exception=argArray[1] /* retrieve SAXException argument */ /* display error message */ .error~say(methName":" "line="exception~getLineNumber",col="exception~getColumnNumber":" pp(exception~getMessage))