List of usage examples for org.dom4j Element getText
String getText();
From source file:cbir.reader.XMLReader.java
License:Open Source License
/** * Parses image information from a given XML file and returns a list of * images with their descriptors (only MPEG_EHD and CEDD extracted by * img(rummager)).//from w w w .j a va 2 s . c o m * * @param file * The given img(rummager) XML file. * @return a list of images with their descriptors. * @throws DocumentException */ public List<ImageContainer> parseXMLFile(File file) throws DocumentException { // Read XML file SAXReader reader = new SAXReader(); Document document = reader.read(file); // Get first Element Element rootElement = document.getRootElement(); // Iterate + get image paths + descriptors // outer loop (Info, Data) for (@SuppressWarnings("rawtypes") Iterator iter = rootElement.elementIterator(); iter.hasNext();) { Element element = (Element) iter.next(); // inner loop (Image Data) for (@SuppressWarnings("rawtypes") Iterator innerIter = element.elementIterator(); innerIter.hasNext();) { Element innerElement = (Element) innerIter.next(); // data loop (Filename, EHD, RGB) for (@SuppressWarnings("rawtypes") Iterator dataIter = innerElement.elementIterator(); dataIter.hasNext();) { // get Filename Element dataElement = (Element) dataIter.next(); String filename = new String(dataElement.getText()); List<Descriptor> descriptors = new LinkedList<Descriptor>(); while (dataIter.hasNext()) { // get descriptors dataElement = (Element) dataIter.next(); if (dataElement.getName().equals("EHD") || dataElement.getName().equals("CEDD")) descriptors.add(readDescriptor(dataElement)); } // construct Image and save in list ImageContainer image = new ImageContainer(filename, descriptors.toArray(new Descriptor[descriptors.size()])); imageList.add(image); } } } return imageList; }
From source file:ch.javasoft.metabolic.parse.SbmlParser.java
License:BSD License
private static void parseAnnotations(Element element, Annotateable annotateable, Map<Annotateable, Map<String, String>> annotations) throws DocumentException { Iterator noteIt = element.elementIterator(ELEMENT_NOTES); while (noteIt.hasNext()) { Element notes = (Element) noteIt.next(); Iterator htmlpIt = notes.elementIterator(ELEMENT_HTML_P); while (htmlpIt.hasNext()) { Element note = (Element) htmlpIt.next(); String txt = note.getText(); String[] keyVal = txt.trim().split(":"); if (keyVal.length != 2) { throw new DocumentException("invalid annotation format: " + txt); }//from w w w . jav a 2 s.c o m String key = keyVal[0].trim(); String val = keyVal[1].trim(); getAnnotationMap(annotations, annotateable, true).put(key, val); } } }
From source file:classes.WebServiceCep.java
License:Open Source License
/** * Faz uma busca a partir do cep enviado, no site * <a href="http://www.republicavirtual.com.br" * target="_blank">republicavirtual.com.br</a>, retornando o resultado em um objeto * {@link WebServiceCep}./* w ww . j a v a 2 s . c om*/ * <BR> * <BR>No se faz necessrio formataes, a string pode ser enviada em qualquer * formatao, pois s sero consideradas os primeiros 8 numeros da string. * <BR>Por Exemplo: * <BR>Uma <tt>{@link String} "14.568-910"</tt> automaticamente passada para * <tt>"14568910"</tt>. * <BR>Uma <tt>{@link String} "1%4#5?55%16a8&910"</tt> automaticamente passada para * <tt>"14555168"</tt>, s levando em conta os primeiros 8 nmeros. * @param cep Nmero do cep a ser carregado. S sero considerados os primeiros 8 * nmeros da {@link String} enviada. Todos os caracters no numricos sero * removidos, e a string ser truncada caso seja maior que 8 caracters. * @return {@link WebServiceCep} contendo as informaes da pesquisa. */ public static WebServiceCep searchCep(String cep) { cep = cep.replaceAll("\\D*", ""); //To numeric digits only if (cep.length() > 8) cep = cep.substring(0, 8); WebServiceCep loadCep = new WebServiceCep(cep); try { XmlEnums enums = new XmlEnums(); for (Element e : getElements(cep)) enums.getXml(e.getQualifiedName()).setCep(e.getText(), loadCep); } catch (DocumentException ex) { if (ex.getNestedException() != null && ex.getNestedException() instanceof java.net.UnknownHostException) { loadCep.setResultText("Site no encontrado."); loadCep.setResulCode(-14); } else { loadCep.setResultText("No foi possivel ler o documento xml."); loadCep.setResulCode(-15); } loadCep.setExceptio(ex); } catch (MalformedURLException ex) { loadCep.setExceptio(ex); loadCep.setResultText("Erro na formao da url."); loadCep.setResulCode(-16); } catch (Exception ex) { loadCep.setExceptio(ex); loadCep.setResultText("Erro inesperado."); loadCep.setResulCode(-17); } return loadCep; }
From source file:cms.service.template.TemplateXml.java
private void parseRecord(Element record) { List<Element> fileds = record.elements(); dbobject = doc.getRootElement().getName(); fields = new String[fileds.size()]; datatype = new String[fileds.size()]; value = new String[fileds.size()]; index = new int[fileds.size()]; //set query//from w ww . j ava 2s.c o m insertquery = "\tinsert into table_" + dbobject + "( " + (isparent ? "" : relfield + ","); insertvalue = ")values(" + (isparent ? "" : "'0',"); updatequery = "\tupdate table_" + dbobject + " set "; colcount = 0; for (Element field : fileds) { String elmXml = field.asXML(); String fname = field.getName(); String fvalue = field.getText(); fields[colcount] = field.getName(); datatype[colcount] = field.attributeValue("type"); index[colcount] = colcount; setValue(fvalue, field.getName(), field.attributeValue("type"), field.attributeValue("isRequired")); } makeSql(); }
From source file:cms.service.util.ItemUtility.java
License:Open Source License
public HashMap<String, String> getItemValueMap(String xml) { List<Element> itemlist; List<Element> items; HashMap<String, String> varmap = new HashMap<String, String>(); Element root = this.getRootElementFromXML(xml); if (root != null) { items = root.elements();/*from ww w . java 2 s. c o m*/ if (items.size() == 1 && items.get(0).hasContent()) { itemlist = items.get(0).elements(); } else { itemlist = items; } for (Element var : itemlist) { String name = var.getName(); String value = var.getText(); varmap.put(name, value); } } return varmap; }
From source file:cn.b2b.index.product.create.ProductDataFromDB.java
private String getBrand(String xml) { Document doc;/* w w w . j av a2 s . co m*/ try { doc = DocumentHelper.parseText(xml); Element rootNode = doc.getRootElement(); Iterator iter = rootNode.nodeIterator(); while (iter.hasNext()) { Element recordEle = (Element) iter.next(); String title = recordEle.getName(); if (title.equals("P1")) { return recordEle.getText(); } return ""; } } catch (DocumentException e) { // e.printStackTrace(); } return ""; }
From source file:cn.b2b.index.product.create.ProductDataFromDB.java
private String getItemByXml(String xml, String nodeName) { Document doc;/* w w w . ja v a 2 s . c om*/ try { doc = DocumentHelper.parseText(xml); Element rootNode = doc.getRootElement(); Iterator iter = rootNode.nodeIterator(); while (iter.hasNext()) { Element recordEle = (Element) iter.next(); String title = recordEle.getName(); if (title.equals(nodeName)) { return recordEle.getText(); } return ""; } } catch (DocumentException e) { // e.printStackTrace(); } return ""; }
From source file:cn.com.sinosoft.ebusiness.xmltransfer.PolicyDetailCreater.java
@Override public Map<String, Object> Xml2Object(Document doc) { log.info("PolicyDetailCreaterXml2Object...."); Map<String, Object> result = new HashMap<String, Object>(); try {//from w ww . ja va 2s .com result.put("flag", doc.selectSingleNode(sTranResponse + "/Flag").getText()); Element desc = (Element) doc.selectSingleNode(sTranResponse + "/Desc"); result.put("desc", desc.getText()); // Policy policy = new Policy(); if (doc.selectSingleNode(sTranResponse + "/Flag").getText().equals("1")) { Element tLccont = (Element) doc.selectSingleNode(sTranResponse + "/LCCont"); // String policyNo = tLccont.element("ContNo").getText(); policy.setPolicyNo(policyNo); // NETS String souseFlag = tLccont.element("SouseFlag").getText(); policy.setSource(souseFlag); // policy.setRiskAccount(getRiskAccount(tLccont)); // getPolicyInfo(tLccont, policy); // Element tLCAppnt = (Element) doc.selectSingleNode(sTranResponse + "/LCCont/LCAppnt"); policy.setAppnt(getAppntByPolicyNo(tLCAppnt)); // Element tLCInsureds = (Element) doc.selectSingleNode(sTranResponse + "/LCCont/LCInsureds"); // Element tLCInsured = (Element) tLCInsureds.elements("LCInsured").get(0); policy.setInsured(getInsuredByPolicyNo(tLCInsured, policy)); result.put("policy", policy); } } catch (Exception e) { log.info("" + e.getMessage()); result.put("flag", "0"); result.put("desc", "...."); e.printStackTrace(); } return result; }
From source file:cn.com.sinosoft.ebusiness.xmltransfer.PolicyDetailCreater.java
/** * //from w ww .j av a2 s . c o m * * @param tLCAppnt * @return */ @SuppressWarnings("unchecked") private List<Beneficiary> getBnfsByPolicy(Element eRisk) { NumberFormat nt = NumberFormat.getPercentInstance(); nt = NumberFormat.getPercentInstance(); nt.setMaximumIntegerDigits(3); nt.setMaximumFractionDigits(2); List<Beneficiary> beneficiarys = new ArrayList<Beneficiary>(); Element eLCBnfs = eRisk.element("LCBnfs"); Element tLCBnfCount = eLCBnfs.element("LCBnfCount"); if (Integer.parseInt(tLCBnfCount.getText()) > 0) { List<Element> tLCBnfs = eLCBnfs.elements("LCBnf"); for (Element tLCBnf : tLCBnfs) { Beneficiary beneficiary = new Beneficiary(); // beneficiary.setBeneficiaryOrder( IntegerToChinese.ConvertToChinese(Integer.parseInt(tLCBnf.element("BnfGrade").getText()))); beneficiary.setName(tLCBnf.element("Name").getText()); double bnfPercent = Double.parseDouble(tLCBnf.element("BnfLot").getText()); beneficiary.setInterestPercent(nt.format(bnfPercent)); beneficiarys.add(beneficiary); } } return beneficiarys; }
From source file:cn.com.sunjiesh.wechat.service.AbstractWechatMessageReceiveService.java
/** * ??//from w w w. j a v a2s . c o m * * @param doc4j ??Dom * @param toUserName ?? * @param fromUserName ????OpenID * @param eventKey KEY??? * @param event event * @return ? */ protected WechatReceiveEventPicCommonMessage getWechatReceiveEventPicCommonMessage(Document doc4j, String toUserName, String fromUserName, String eventKey, String event) { Element sendPicsInfoEle = (Element) doc4j.selectSingleNode("/xml/SendPicsInfo"); Element countNode = sendPicsInfoEle.element("Count"); List<Element> picListNodeList = sendPicsInfoEle.elements("PicList"); Integer count = Integer.parseInt(countNode.getText()); WechatReceiveEventPicCommonMessage wechatMessage = new WechatReceiveEventPicCommonMessage(toUserName, fromUserName, event, eventKey); wechatMessage.setCount(count); picListNodeList.forEach(node -> { Element itemEle = node.element("item"); Element picMd5SumEle = itemEle.element("PicMd5Sum"); String picMd5Sum = picMd5SumEle.getTextTrim(); wechatMessage.getPicsInfoList().add(wechatMessage.new SendPicsInfo(picMd5Sum)); }); return wechatMessage; }