[b]eachdata.xml[/b]
<?xml version="1.0" encoding="UTF-8"?>
<eachdata>
<countnum>
<payingblock>alipay@et361.com</payingblock><!-- 平台支付宝 -->
</countnum>
</eachdata>
解析
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
File file = new File(path + File.separator + "eachdata" + File.separator + "eachdata.xml");
// System.out.println(file.getPath());
Document doc = docBuilder.parse (file.getPath());
doc.getDocumentElement ().normalize ();
NodeList listOfPersons = doc.getElementsByTagName("countnum");
for(int s=0; s<listOfPersons.getLength() ; s++){
Node firstPersonNode = listOfPersons.item(s);
if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){
Element firstPersonElement = (Element)firstPersonNode;
NodeList payingblockList = firstPersonElement.getElementsByTagName("payingblock");
Element payingblockElement = (Element)payingblockList.item(0);
NodeList textpayingblockList = payingblockElement.getChildNodes();
System.out.println(((Node)textpayingblockList.item(0)).getNodeValue().trim());
<?xml version="1.0" encoding="UTF-8"?>
<eachdata>
<countnum>
<payingblock>alipay@et361.com</payingblock><!-- 平台支付宝 -->
</countnum>
</eachdata>
解析
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
File file = new File(path + File.separator + "eachdata" + File.separator + "eachdata.xml");
// System.out.println(file.getPath());
Document doc = docBuilder.parse (file.getPath());
doc.getDocumentElement ().normalize ();
NodeList listOfPersons = doc.getElementsByTagName("countnum");
for(int s=0; s<listOfPersons.getLength() ; s++){
Node firstPersonNode = listOfPersons.item(s);
if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){
Element firstPersonElement = (Element)firstPersonNode;
NodeList payingblockList = firstPersonElement.getElementsByTagName("payingblock");
Element payingblockElement = (Element)payingblockList.item(0);
NodeList textpayingblockList = payingblockElement.getChildNodes();
System.out.println(((Node)textpayingblockList.item(0)).getNodeValue().trim());