コード例 #1
0
  @Override
  public void parseFile() {

    final Document doc;

    try {
      final File xmlFile = new File(fileLoc);
      final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
      final DocumentBuilder dbBuilder;
      dbBuilder = dbFactory.newDocumentBuilder();
      doc = dbBuilder.parse(xmlFile);
      doc.getDocumentElement().normalize();
    } catch (ParserConfigurationException | SAXException | IOException e) {
      logger.error("Unable to parse xml file due to: \n" + e);
      return;
    }

    final NodeList nodeList = doc.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
      final Node node = nodeList.item(i);
      final String nodeName = node.getNodeName();
      XmlAttributeType xmlAttributeType = XmlAttributeType.valueOf(nodeName.toUpperCase());

      if (xmlAttributeType == XmlAttributeType.DATA) {
        recurseDocument(node);
      }

      int p = 0;
    }
  }
コード例 #2
0
  private void recurseDocument(Node node) {

    final NodeList nodeList = node.getChildNodes();

    for (int i = 0; i < nodeList.getLength(); i++) {
      final Node childNode = nodeList.item(i);
      final String nodeName = childNode.getNodeName();
      XmlAttributeType xmlAttributeType = XmlAttributeType.valueOf(nodeName.toUpperCase());

      switch (xmlAttributeType) {
        case VARIABLE:
          parseVariableNode(childNode);
          break;
        case ENTRY:
          parseEntryNode(childNode);
          break;
      }
    }
  }