0
問題是爲什麼我無法從rootElement中找到任何屬性?通過遞歸方法在xml中打印所有屬性
我的XML是
<?xml version="1.0" encoding="GBK"?>
<AccountInfos>
<!--this is a test for dom4j-->
<AccountInfo1 WebsiteName="ÐÂÀË" Account="123">Account1</AccountInfo1>
<AccountInfo2 WebsiteName="ÍøÒ×" Account="123">Account2</AccountInfo2>
</AccountInfos>
,我的代碼是這樣的
private void treeWalker(Element element)
{
int size = element.nodeCount();
for (int i = 0; i < size; i++)
{
Node node = element.node(i);
if (node instanceof Element)
{
treeWalker((Element) node);
}
else if(node instanceof Attribute)
{
Attribute attribute=(Attribute)node;
System.out.println(attribute.getName()+":"+attribute.getValue());
}
else
{
continue;
}
}
}
,當我在這個方法調試我不能進入第二個if塊
非常感謝 – Marc