我正在尝试替换Value
中OMElement
标记中的值。
我的代码只添加到它(它下面的564.12值)。
<b:UI022002D>
<b:Description>Box 2a (Taxable Amount)</b:Description>
<b:UIRef>UI022002D</b:UIRef>
<b:Value>564.1200</b:Value>
564.12
</b:UI022002D>
代码:
ArrayList
<OMElement>
aElem=getChildrenByPath(oForm, xpathNonUniueTag);
for(int i=0;i <aElem.size();i++) {
OMElement elem=aElem.get(i);
if (xpathNonUniueTag=="*/AmountFields/FormAmountField") {
if (sValue.length()> 2){
elem.setText(getChildText(elem, "Value").substring(0, sValue.length() - 2));
}
}
}
答案 0 :(得分:1)
找到我的答案:
private void mapNonUniqueNodes(OMElement oForm, String sFormID, String xpathNonUniueTag, String xpathChildNodeWithUniqueTag,
String sDescTag)
{
ArrayList<OMElement> aElem=getChildrenByPath(oForm, xpathNonUniueTag);
for(int i=0;i<aElem.size();i++)
{
OMElement elem=aElem.get(i);
String newTagName=getChildText(elem, xpathChildNodeWithUniqueTag);
newTagName=newTagName.replace("-", "");
String sDescTagValue=getChildText(elem, sDescTag);
if (xpathNonUniueTag == "*/AmountFields/FormAmountField") {
ArrayList<OMElement> aElem2=getChildrenByPath(elem, "*/Value");
log.info("aElem2 " + aElem2);
for(int e=0;e<aElem2.size();e++)
{
OMElement elem2=aElem2.get(e);
String sValue = elem2.getText();
if (sValue.length() > 2){
sValue = sValue.substring(0, sValue.length() - 2);
elem2.setText(sValue);
log.info("elem2 " + elem2);
log.info("elem2 text " + elem2.getText());
}
}
}
}