DOM XML Parser Example

后端 未结 3 1445
春和景丽
春和景丽 2020-11-30 10:46

I have this XML file.I just parse this XML file.This example shows how to get the node by “name”, and display the value.How to show all records from database?



        
3条回答
  •  囚心锁ツ
    2020-11-30 11:09

    I don't think your XML is valid -- you're only allowed to have one root element in XML.

    So when you do:

    NodeList nList = doc.getElementsByTagName("record");
    

    You're only going to get one element. which is that first ...

    In order to fix this, you'll need to wrap all of your tags in some sort of a root element like this:

    
      
        1
      
      
        2
      
      ...
    
    

    and you'll have to say:

    NodeList nList = doc.getDocumentElement().getElementsByTagName("record");
    

提交回复
热议问题