package com.eplian.wechat.core.message.receive;

/**
 * Created with IntelliJ IDEA.
 * User: www
 * Date: 13-9-1
 * Time: 下午11:29
 * To change this template use File | Settings | File Templates.
 */
import com.eplian.wechat.core.message.reply.RplMsg;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;

import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.jdom2.Attribute;

public class RecvMsg {
    /**
     * content, such as text, image url, link etc
     */
    public Map<String,String> map=new HashMap<String,String>();

    public RecvMsg(InputStream is)throws IOException,JDOMException{
        SAXBuilder saxBuilder = new SAXBuilder();
        Document document = saxBuilder.build(is);
        this.parseMsg(document);
    }

    private void parseMsg(Document document){
        Element root = document.getRootElement();
        Iterator it_attr = root.getAttributes().iterator();
        while (it_attr.hasNext()) {
            Attribute attribute = (Attribute) it_attr.next();
            String attrname = attribute.getName();
            String attrvalue = root.getAttributeValue(attrname);
            map.put( attrname, attrvalue);
        }
    }
    /**
     * 获取消息的值
     * @param key
     * @return
     */
    public String get(String key){
        return map.get(key);
    }
}

@@ -1060,18 +1060,16 @@
 .get
-Attributes
+Children
 ().i
@@ -1133,40 +1133,34 @@
     
-Attribute attribute = (Attribute
+Element element = (Element
 ) it
@@ -1197,28 +1197,22 @@
 ing 
-attr
 name = 
-attribute
+element
 .get
@@ -1243,20 +1243,16 @@
 ing 
-attr
 value = 
 root
@@ -1251,39 +1251,28 @@
 e = 
-root.getAttributeValue(attrname
+element.getTextTrim(
 );%0D%0A
@@ -1296,22 +1296,14 @@
 ut( 
-attr
 name, 
-attr
 valu

fix bug