我有一个如下格式的XML;Java - 二维数组 - 阵列的最后一行的唯一值正在被正确赋值余数被赋值为空
<TestCase>
<Step Sel = "deleteAllVisibleCookies" Obj = "All cookies" Val = ""></Step>
<Step Sel = "open" Obj = "URL" Val = "UserName:Password"></Step>
<Step Sel = "waitForElementPresent" Obj = "link=mobile" Val = ""></Step>
<Step Sel = "clickAndWait" Obj = "Mobile link" Val = ""></Step>
...
</TestCase>
<TestCase>
<Step Sel = "deleteAllVisibleCookies" Obj = "All cookies" Val = ""></Step>
<Step Sel = "open" Obj = "URL" Val = "UserName:Password"></Step>
<Step Sel = "waitForElementPresent" Obj = "link=mobile" Val = ""></Step>
<Step Sel = "clickAndWait" Obj = "Mobile link" Val = ""></Step>
...
</TestCase>
基于上述XML文件,我正在创建一个对象。我试图将所有步骤保存到二维数组中。所以一行是一个测试用例。其中我面临
int i=0;
int j=0;
for (int TC = 0; TC < TCLst.getLength(); TC++)
int k=0;
Node TCLstNode = TCLst.item(TC);
if (TCLstNode.getNodeType() == Node.ELEMENT_NODE)
{
NodeList StepLst = TCLstNode.getChildNodes();
Step = new String [TCCount][StepLst.getLength()];//defining total length
Sel = new String [TCCount][StepLst.getLength()];
Obj = new String [TCCount][StepLst.getLength()];
Val = new String [TCCount][StepLst.getLength()];
for (int Step = 0; Step < StepLst.getLength(); Step++)
{
Node StepLstNode = StepLst.item(Step);
if (StepLstNode.getNodeType() == Node.ELEMENT_NODE)
{
if (StepLstNode.getNodeName() == "Step")
{
Sel[i][k] = ObjectType.getAttribute(StepLstNode,"Sel");//returns value of Sel attribute
Obj[i][k] = ObjectType.getAttribute(StepLstNode,"Obj");
Val[i][k] = ObjectType.getAttribute(StepLstNode,"Val");
stepCountInTC++;
k++;
}
}//NodeType
}//for
i++;
stepCountInATCOfModule[j] = stepCountInTC;
j++;
stepCountInTC = 1;
}//TC if
问题是在创建对象后,上打印二维阵列我得到输出中的任何一个(在这里,我使用SEL属性);
[NULL,NULL,NULL,NULL,...] [deleteAllVisibleCookies,开放,waitForElementPresent,clickAndWait,...]]
问题就在这里的第一个测试用例值保存为空。如果我在3个测试用例中使用XML,那么前2个测试用例保存为空,第三个用例保存到数组中。
也请建议任何集合使用,而不是二维数组。
使用''==不要比较字符串。在if(StepLstNode.getNodeName()==“Step”)中使用'.equals()'...' – Albert