xml字符串内容格式为
<Items><WFItem name="FORM" type="1280" >frmTmpsqlDoc</WFItem>WFItem name="WF_DocUNID" type="1280" >1577E78C881356F648257FFF0033E1D5</WFItem><WFItem name="WF_AddName" type="1280" >admin</WFItem><WFItem name="WF_AddName_CN" type="1280" >系统管理员</WFItem>
</Items>
通过解析获取name以及对应的value值
import java.util.Iterator;
import java.util.List;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
public static void main(String[] args) throws Exception { String xml = "<Items><WFItem name=\"FORM\" type=\"1280\" >frmTmpsqlDoc</WFItem><WFItem name=\"WF_OrUNID\" type=\"1280\" >1577E78C881356F648257FFF0033E1D5</WFItem><WFItem name=\"WF_EndDeptName\" type=\"1280\" >xx学院</WFItem></Items>"; Document document = DocumentHelper.parseText(xml); Element root = document.getRootElement(); List<Element> elements = root.elements(); for (Iterator<Element> it = elements.iterator(); it.hasNext();) { Element element = it.next(); List<Attribute> attributes = element.attributes(); for (int i = 0; i < attributes.size(); i++) { Attribute attribute = attributes.get(i); if ("name".equals(attribute.getName())) { System.out.println("name=" + attribute.getText() + ",value=" + element.getText()); } } } }
输出结果: name=FORM,value=frmTmpsqlDoc name=WF_OrUNID,value=1577E78C881356F648257FFF0033E1D5 name=WF_EndDeptName,value=xx学院
--可参考OA接口 查看待办事项详情