如何解析这种格式数据

java远程调用的webService的接口 但是返回的数据类型该如何解析 我用的是xml解析都不行
麻烦请大神看一下

要解析的数据

  • ``` 我的解析方法
<Integration>
  <GetDepartments>
    <Head>
      <ErrCode>0</ErrCode>
      <ErrMsg>成功</ErrMsg>
    </Head>
    <Body>
      <Item>
        <DeptID>1</DeptID>
        <DeptCode>0001</DeptCode>
        <DeptName><![CDATA[Head Office]]></DeptName>
        <Director></Director>
        <ParentDeptID>0</ParentDeptID>
        <ParentDeptCode>0</ParentDeptCode>
        <ParentDeptName><![CDATA[]]></ParentDeptName>
        <PersonNum>1</PersonNum>
        <Remark><![CDATA[]]></Remark>
      </Item>
      ...
    </Body>
  </GetDepartments>
</Integration>


我的解析方法

doc = DocumentHelper.parseText(String.valueOf(returnObj));
Element root = doc.getRootElement();
root.elementText("ErrCode")

图片说明

https://www.cnblogs.com/hongwz/p/5514786.html

你的“我用的是xml解析都不行” 你说的找个不行,是啥意思呢? xml的每个标签里面有name,属性等很多内容,我猜测你应该是是说取不到值吧。

找个你不能指望一两行代码自动出来,你肯定需要自己定义一个类,数据结构和找个xml对应。所谓解析就是把xml信息提取到找个java对象里面去
然后搜索“解析自定义的xml”,在github上很多例子的。你试试下面的。

注意,xml标签看里面,有标签name ,属性key,属性值等等许多概念,取值的时候,到底需要啥,要注意
https://www.cnblogs.com/wumingxuanji/p/9561163.html
https://blog.csdn.net/qq_23025855/article/details/79363388
https://www.cnblogs.com/keyi/p/6137721.html
https://blog.csdn.net/u011277123/article/details/64906127

使用pullparse