コード例 #1
0
ファイル: SamplePaseXml.java プロジェクト: myothercode/tembin
 /**
  * 通过Title 查询是相似分类信息
  *
  * @param xml
  * @return
  * @throws DocumentException
  */
 public static List<TradingReseCategory> selectCategoryByKey(String xml) throws Exception {
   List<TradingReseCategory> litrc = new ArrayList();
   // 商品分类目录查询
   Document document = formatStr2Doc(xml);
   Element rootElt = document.getRootElement();
   if (rootElt == null) {
     return litrc;
   }
   Element recommend = rootElt.element("SuggestedCategoryArray");
   if (recommend == null) {
     return litrc;
   }
   Iterator<Element> ite = recommend.elementIterator("SuggestedCategory");
   while (ite.hasNext()) {
     Element ele = ite.next();
     Element cate = ele.element("Category");
     Element PercentItemFound = ele.element("PercentItemFound");
     TradingReseCategory trc = new TradingReseCategory();
     trc.setId(Long.parseLong(cate.elementText("CategoryID")));
     trc.setCategoryId(cate.elementText("CategoryID"));
     Iterator<Element> ites = cate.elementIterator("CategoryParentName");
     String cateName = "";
     while (ites.hasNext()) {
       Element ent = ites.next();
       cateName = cateName + ent.getText() + ":";
     }
     trc.setCategoryKey(PercentItemFound.getText() + "%");
     trc.setCategoryName(cateName + cate.elementText("CategoryName"));
     litrc.add(trc);
   }
   return litrc;
 }
コード例 #2
0
ファイル: SamplePaseXml.java プロジェクト: myothercode/tembin
  /**
   * 通过Title 商品所属分类查询
   *
   * @param xml
   * @param key
   * @return
   * @throws DocumentException
   */
  public static List<TradingReseCategory> selectCategoryBytitle(String xml, String key)
      throws Exception {
    List<TradingReseCategory> litrc = new ArrayList();
    // 之前是做商品所属分类查询
    Document document = formatStr2Doc(xml);
    Element rootElt = document.getRootElement();
    Element recommend = rootElt.element("searchResult");
    Iterator<Element> iter = recommend.elementIterator("item");
    while (iter.hasNext()) {
      Element ele = iter.next();
      Element elecate = ele.element("primaryCategory");
      TradingReseCategory trc = new TradingReseCategory();
      trc.setId(Long.parseLong(elecate.elementText("categoryId")));
      trc.setCategoryId(elecate.elementText("categoryId"));
      trc.setCategoryName(StringEscapeUtils.escapeHtml(elecate.elementText("categoryName")));
      trc.setCategoryKey(key);
      litrc.add(trc);
    }

    return litrc;
  }