主题:一个关于强制转换的问题
public static void main(String args[])
{
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
try
{
DocumentBuilder db=dbf.newDocumentBuilder();
Document d=db.parse(new File("B.xml"));
NodeList nl=d.getElementsByTagName("table1");
NodeList n2=d.getElementsByTagName("table2");
int len1=nl.getLength();
int len2=n2.getLength();
System.out.println(len1);
for(int i=0;i <len1;i++)
{
[color=FF0000]Element stu=(Element)nl.item(i);[/color]
NodeList e1=stu.getElementsByTagName("reportrow");
int len11=e1.getLength();
System.out.println(len11);
for(int j=0;j <len11;j++)
{
Element report=(Element)e1.item(j);
Node project=report.getElementsByTagName("项目").item(0);
String project1=project.getFirstChild().getNodeValue();
System.out.println(project1);
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
解释红色部分,为什么能实现这样的强制转换!谢谢
{
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
try
{
DocumentBuilder db=dbf.newDocumentBuilder();
Document d=db.parse(new File("B.xml"));
NodeList nl=d.getElementsByTagName("table1");
NodeList n2=d.getElementsByTagName("table2");
int len1=nl.getLength();
int len2=n2.getLength();
System.out.println(len1);
for(int i=0;i <len1;i++)
{
[color=FF0000]Element stu=(Element)nl.item(i);[/color]
NodeList e1=stu.getElementsByTagName("reportrow");
int len11=e1.getLength();
System.out.println(len11);
for(int j=0;j <len11;j++)
{
Element report=(Element)e1.item(j);
Node project=report.getElementsByTagName("项目").item(0);
String project1=project.getFirstChild().getNodeValue();
System.out.println(project1);
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
解释红色部分,为什么能实现这样的强制转换!谢谢