2

我有一个SOAPAction返回带有职位的报告列表。位置应按特定顺序排列:按zOrder属性排序

在发送响应之前,对职位列表进行排序:

/*sort the positions in the report before adding it to the list*/
List<Position> orderedPositions = report.getPositions();
Collections.sort(orderedPositions, new Comparator<Position>() {
   @Override
   public int compare(Position position, Position position2) {
      return position.getZOrder().compareTo(position2.getZOrder());
   }
});
report.setPositions(orderedPositions);

我检查了列表的顺序是否正确。

在响应 XML 中,<positions>标记的元素与 java 对象中的元素顺序不同。这些元素似乎根本没有排序。这是一段摘录:

<positions>
   <chapter>911</chapter>
   <chapterType>LPK</chapterType>
   <formId>16972704</formId>
   <materialNumber>121</materialNumber>
   <positionID>S16977468</positionID>
   <positionText>-</positionText>
   <positionType>Work</positionType>
   <quantity>9.0</quantity>
   <quantityUnit>h</quantityUnit>
   <serviceReport>16975051</serviceReport>
   <unitPrice>0.0</unitPrice>
   <xmlId>16977468</xmlId>
   <ZOrder>905</ZOrder>
</positions>
<positions>
   <chapter>0</chapter>
   <chapterType>LPK</chapterType>
   <formId>16972704</formId>
   <materialNumber></materialNumber>
   <positionID>S16977469</positionID>
   <positionText></positionText>
   <positionType>Material</positionType>
   <quantity>1.0</quantity>
   <quantityUnit>St</quantityUnit>
   <serviceReport>16975051</serviceReport>
   <unitPrice>0.0</unitPrice>
   <xmlId>16977469</xmlId>
   <ZOrder>1002</ZOrder>
</positions>
<positions>
   <chapter>0</chapter>
   <chapterType>NPK</chapterType>
   <formId>16972704</formId>
   <materialNumber></materialNumber>
   <positionID>S16977470</positionID>
   <positionText></positionText>
   <positionType>Material</positionType>
   <quantity>2.0</quantity>
   <quantityUnit>St</quantityUnit>
   <serviceReport>16975051</serviceReport>
   <unitPrice>0.0</unitPrice>
   <xmlId>16977470</xmlId>
   <ZOrder>1003</ZOrder>
</positions>
<positions>
   <chapter>0</chapter>
   <chapterType>LPK</chapterType>
   <formId>16972704</formId>
   <materialNumber></materialNumber>
   <positionID>S16977471</positionID>
   <positionText></positionText>
   <positionType>Material</positionType>
   <quantity>3.0</quantity>
   <quantityUnit>St</quantityUnit>
   <serviceReport>16975051</serviceReport>
   <unitPrice>0.0</unitPrice>
   <xmlId>16977471</xmlId>
   <ZOrder>1004</ZOrder>
</positions>

如何获取positions响应 XML 中按ZOrder属性排序的元素?

4

0 回答 0