string xml="<hello><hi a='a' b='b'/><hi a='b' b='a'/></hello>";//read XML from the given stringdocumentBuilderFactory factory = documentBuilderFactory.newInstance();documentBuilder builder = factory.newdocumentBuilder();InputSource is = new InputSource(new StringReader(xml));document doc = builder.parse(is);//this will return a list of xml tags whose name is `hi`NodeList hiList = document.getElementsByTagName("hi");//you can iterate over hiList and read/process themfor (int i = 0; i < hiList.getLength(); i++) { Node child = hiList.item(i); String name = child.getNodeName(); String contents = child.getTextContent();}