已知在d盘下有一个XML文档addressBook.xml,内容如下:
<?xml version=”1.0” encoding=”UTF-8”?>
<addressbook>
<company/>
<person/>
</addressbook>
在J2EE中,要输出addressbook的子节点的个数,以下代码片断正确的是()。(选择一项)
a) DocumentBuilderFactory dbf=DocumentBuilderFactory.newIstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc=db.parse(“d:/addressbook.xml”);
Root r=doc.getRoot();
NodeList nodelist=r.getChildNode();
System.out..println(nodelist.getLength());
b) Document doc=db.parse(“d:/addressbook.xml”);
Element e=doc.getDocument();
NodeList nodeList=e.getChildNodes();
System.out.println(nodeList,getLength());
c) DocumentBuilderFactory dbf=DocumentBuilderFactory.newIstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc=db.parse(“d:/addressbook.xml”);
Element e=doc.getDocument();
NodeList nodelist=r.getChildNode();
System.out..println(nodelist.getLength());
d) Document doc=db.parse(“d:/addressbook.xml”);
Root r=doc.getRoot();
NodeList nodelist=r.getChildNode();
System.out..println(nodelist.getLength());