Extract single quoted html attributes using xpath -
i want extract values of single quoted html attributes using xpath. have used jtidy clean html doc , code looks this:
try { string data = string.tostring(); inputstream input = new bytearrayinputstream(data.getbytes()); document document = new tidy().parsedom(input, null); xpathfactory factory = xpathfactory.newinstance(); xpath xpath = factory.newxpath(); xpathexpression expr = xpath.compile("//a[@class='swatch-2011-link']/@color"); object evaluate = expr.evaluate(document, xpathconstants.nodeset); nodelist list = (nodelist) evaluate; system.out.println(list.getlength()); (int = 0; < list.getlength(); i++) { string name = list.item(i).getnodevalue(); system.out.println(name); } } catch (xpathexpressionexception e) { e.printstacktrace(); } <a class="swatch-2011-link" style='background:url(somelink); background-size:26px 26px; filter:progid:dximagetransform.microsoft.alphaimageloader(src=http://media.plussizetech.com/womanwithin/zs/0037_19561_zs_2835.jpg, sizingmethod=scale)' mainimageurl='http://media.plussizetech.com/womanwithin/mc/0037_19561_mc_2835.jpg?wid=271&hei=388&qlt=95&op_sharpen=1' colorname='wild lime white'/>
Comments
Post a Comment