有没有办法用解析XML文件提供的数据对HashMap(java 1.5)进行充电

时间:2019-05-29 15:28:22

标签: java xml

我正在开发Web应用程序,我需要一些帮助

我已经解析了我的XML文件

我正在尝试将NodeList中包含的元素放入我的hashMap

''JAVA 我的Java代码

public class ReadXMLFile {

public static void main(String[] args) {

    String[][] attributes = { { "s_CODE" }, { "s_CODE_REGATE" }, { "s_LIBELLE" }, { "s_TYPE_ENTITE" },
            { "s_METIER" }, { "s_NUMERO_SIRET" }, { "s_CEA" }, { "s_DEPARTEMENT" }, { "s_RATTACHEMENT" },
            { "s_RATTACHEMENT_UGRH" }, { "G_INFO_RH", "s_RATTACHEMENT_NOD" }, { "d_DATE_DESACTIVATION" },
            { "s_CODE_ADRESSE" } };
    try {

        File f = new File("./src/ok.xml");
        if (!(f.exists() && f.isFile()))
            return;
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();

        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(f);

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

        System.out.println(attributes.length);


          for (int i = 0; i <attributes.length ; i++) {

          Element el = (Element) nList.item(i);

          NodeList listCode = el.getElementsByTagName("s_CODE"); Element element1 =
          (Element) listCode.item(0); Node child1 = element1.getLastChild();
          System.out.println("------------------------------------------------> " +
          child1.getNodeValue());

          NodeList listLibelle = el.getElementsByTagName("s ");
          Element element2= (Element) listLibelle.item(listLibelle.getLength() - 1); 
          Node child2 = element2.getLastChild();
          System.out.println("------------------------------------------------> " +child2.getNodeValue());



          }

0 个答案:

没有答案