// Gets the specified XML Schema doc if one is mentioned in the file
  public static File getSchemaFile(Document xmlDoc) {
    /** @todo Must be an easier way of doing this... */
    logger.logComment("Getting schema file for: " + xmlDoc.getDocumentURI());

    NodeList nl = xmlDoc.getChildNodes();
    for (int j = 0; j < nl.getLength(); j++) {
      Node node = nl.item(j);
      logger.logComment("Type: " + node.getNodeType() + "Name: " + node.getNodeName());
      if (node.getNodeName().equals(XML_STYLESHEET_NODE)) {
        String nodeVal = node.getNodeValue();

        logger.logComment("Looking at: " + nodeVal);
        String xslFileName =
            nodeVal.substring(nodeVal.indexOf("href=\"") + 6, nodeVal.length() - 1);
        File xslFile = new File(xslFileName);
        return xslFile;
      }

      if (node.getAttributes().getLength() > 0) {
        logger.logComment("Attributes: " + node.getAttributes());
        if (node.getAttributes().getNamedItem(XML_SCHEMA_LOC_ATTR) != null) {
          String locString = node.getAttributes().getNamedItem(XML_SCHEMA_LOC_ATTR).getNodeValue();
          logger.logComment("Loc string: " + locString);
          String file = locString.split("\\s")[1];
          return new File(file);
        }
      }
    }
    logger.logError("No node found with name: " + XML_STYLESHEET_NODE);
    return null;
  }
Example #2
0
  private void loadFromXml(String fileName)
      throws ParserConfigurationException, SAXException, IOException, ParseException {
    System.out.println("NeuralNetwork : loading network topology from file " + fileName);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = factory.newDocumentBuilder();
    Document doc = parser.parse(fileName);

    Node nodeNeuralNetwork = doc.getDocumentElement();
    if (!nodeNeuralNetwork.getNodeName().equals("neuralNetwork"))
      throw new ParseException(
          "[Error] NN-Load: Parse error in XML file, neural network couldn't be loaded.", 0);
    // nodeNeuralNetwork ok
    // indexNeuralNetworkContent -> indexStructureContent -> indexLayerContent -> indexNeuronContent
    // -> indexNeuralInputContent
    NodeList nodeNeuralNetworkContent = nodeNeuralNetwork.getChildNodes();
    for (int innc = 0; innc < nodeNeuralNetworkContent.getLength(); innc++) {
      Node nodeStructure = nodeNeuralNetworkContent.item(innc);
      if (nodeStructure.getNodeName().equals("structure")) { // for structure element
        NodeList nodeStructureContent = nodeStructure.getChildNodes();
        for (int isc = 0; isc < nodeStructureContent.getLength(); isc++) {
          Node nodeLayer = nodeStructureContent.item(isc);
          if (nodeLayer.getNodeName().equals("layer")) { // for layer element
            NeuralLayer neuralLayer = new NeuralLayer(this);
            this.listLayers.add(neuralLayer);
            NodeList nodeLayerContent = nodeLayer.getChildNodes();
            for (int ilc = 0; ilc < nodeLayerContent.getLength(); ilc++) {
              Node nodeNeuron = nodeLayerContent.item(ilc);
              if (nodeNeuron.getNodeName().equals("neuron")) { // for neuron in layer
                Neuron neuron =
                    new Neuron(
                        Double.parseDouble(((Element) nodeNeuron).getAttribute("threshold")),
                        neuralLayer);
                neuralLayer.listNeurons.add(neuron);
                NodeList nodeNeuronContent = nodeNeuron.getChildNodes();
                for (int inc = 0; inc < nodeNeuronContent.getLength(); inc++) {
                  Node nodeNeuralInput = nodeNeuronContent.item(inc);
                  // if (nodeNeuralInput==null) System.out.print("-"); else System.out.print("*");

                  if (nodeNeuralInput.getNodeName().equals("input")) {
                    //                                        System.out.println("neuron at
                    // STR:"+innc+" LAY:"+isc+" NEU:"+ilc+" INP:"+inc);
                    NeuralInput neuralInput =
                        new NeuralInput(
                            Double.parseDouble(((Element) nodeNeuralInput).getAttribute("weight")),
                            neuron);
                    neuron.listInputs.add(neuralInput);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
Example #3
0
  private List<Node> getChildNodes(Node parentNode, String tagName) {
    List<Node> nodeList = new ArrayList<Node>();
    for (Node child = parentNode.getFirstChild(); child != null; child = child.getNextSibling()) {
      if (child.getNodeType() == Node.ELEMENT_NODE && tagName.equals(child.getNodeName())) {
        nodeList.add(child);
      }
    }

    return nodeList;
  }
Example #4
0
 private String getXPath(Node node, String xpath) {
   if (node == null) {
     return "";
   }
   String nodeName = node.getNodeName();
   Node parent = node.getParentNode();
   if (parent == null) {
     return xpath;
   }
   return getXPath(parent, "/" + nodeName + xpath);
 }
Example #5
0
 private void call(Node operation)
     throws ParserConfigurationException, TransformerConfigurationException {
   String opName = operation.getNodeName();
   if (opName.equals("call")) {
     String script =
         Utils.combine(Utils.getParentDir(this.currentScript), operation.getTextContent());
     call(script);
   } else if (opName.equals("apply")) processApply(operation);
   else if (opName.equals("xml")) processXml(operation);
   else if (opName.equals("txt")) processTxt(operation);
   else if (opName.equals("copy")) processCopy(operation);
   else if (opName.equals("delete")) processDelete(operation);
 }
Example #6
0
 /**
  * Returns the full name (i.e. the name including an eventual namespace prefix) of the element.
  *
  * @webref xml:method
  * @brief Gets the element's full name
  * @return the name, or null if the element only contains #PCDATA.
  */
 public String getName() {
   //    return name;
   return node.getNodeName();
 }