Example usage for org.dom4j Node selectSingleNode

List of usage examples for org.dom4j Node selectSingleNode

Introduction

In this page you can find the example usage for org.dom4j Node selectSingleNode.

Prototype

Node selectSingleNode(String xpathExpression);

Source Link

Document

selectSingleNode evaluates an XPath expression and returns the result as a single Node instance.

Usage

From source file:GnuCash.Transaction.java

License:Open Source License

static void addTransactions(Vector<Transaction> transactions, Node n, String account_id) {
    List<Node> NL = n.selectNodes("trn:splits[trn:split[split:account='" + account_id + "']]/trn:split");

    for (int i = 0; i < NL.size(); i++) {

        Transaction t = new Transaction();
        t.description = n.selectSingleNode("trn:description").getText();
        t.currency_id = n.selectSingleNode("trn:currency/cmdty:id").getText();
        t.date = getDateValue(n.selectSingleNode("trn:date-posted/ts:date").getText());

        t.value = getDoubleValue(NL.get(i).selectSingleNode("split:value").getText());

        if (NL.get(i).selectSingleNode("split:account[@type='guid']").getText().equals(account_id)) {
            t.quantity = getDoubleValue(NL.get(i).selectSingleNode("split:quantity").getText());
        }/*  w  ww .  ja va 2  s. c o m*/

        transactions.add(t);
    }
}

From source file:hebbNet.HebbNet.java

License:Open Source License

@Override
public AbstractRepresentation loadFromXML(Node nd) {
    try {/*from www.  j a  v a2s  .  c  o  m*/
        // Add properties
        loadProperties();
        this.learningrate = Float.parseFloat(nd.valueOf("./@learningrate"));
        this.input_nodes = Integer.parseInt(nd.valueOf("./@input_nodes"));
        this.output_nodes = Integer.parseInt(nd.valueOf("./@output_nodes"));
        this.nodes = Integer.parseInt(nd.valueOf("./@nodes"));
        this.weight_range = Float.parseFloat(nd.valueOf("./@weight_range"));
        this.bias_range = Float.parseFloat(nd.valueOf("./@bias_range"));
        this.activation = new float[this.nodes];
        this.output = new float[this.nodes];
        this.bias = new float[this.nodes];
        this.weight = new float[this.nodes][this.nodes];
        this.plasticity = new float[this.nodes][this.nodes];
        this.currentweight = new float[this.nodes][this.nodes];
        Node dnodes = nd.selectSingleNode("./nodes");
        for (int nr = this.input_nodes; nr < this.nodes; nr++) {
            Node curnode = dnodes.selectSingleNode("./node[@nr='" + nr + "']");
            if (curnode == null)
                throw new IllegalArgumentException("HebbNet: node tags inconsistent!"
                        + "\ncheck 'nr' attributes and nodes count in nnetwork!");
            this.bias[nr] = Float.parseFloat(curnode.valueOf("./bias"));
            Node dweights = curnode.selectSingleNode("./weights");
            for (int from = 0; from < this.nodes; from++) {
                Node thisweight = dweights.selectSingleNode("./weight[@from='" + from + "']");
                float plast = Float.parseFloat(thisweight.valueOf("./@plasticity"));
                float weight = Float.parseFloat(thisweight.valueOf("."));
                this.weight[from][nr] = weight;
                this.plasticity[from][nr] = plast;
            }
        }
        resetWeights();
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("HebbNet: NumberFormatException! Check XML File");
    }
    return this;
}

From source file:io.mashin.oep.hpdl.XMLReadUtils.java

License:Open Source License

public static void initTextPropertyFrom(ModelElement model, String prop, TextPropertyElement pe, String xpath,
        Node node) {
    model.setPropertyValue(prop, valueOf(node.selectSingleNode(xpath)));
}

From source file:io.mashin.oep.hpdl.XMLReadUtils.java

License:Open Source License

public static void initTextPropertyFrom(TextPropertyElement pe, Node node, String xpath) {
    pe.setStringValue(valueOf(node.selectSingleNode(xpath)));
}

From source file:io.mashin.oep.hpdl.XMLReadUtils.java

License:Open Source License

public static void initCheckPropertyFrom(CheckBoxPropertyElement pe, Node node, String xpath) {
    pe.setValue(node.selectSingleNode(xpath) != null);
}

From source file:io.mashin.oep.hpdl.XMLReadUtils.java

License:Open Source License

@SuppressWarnings("unchecked")
public static void initPropertiesCollectionFrom(PropertyElementCollection pec, Node node, String groupXPath,
        String propertyXPath) {//from  w  w  w  .  j  a  v  a  2s .  co m
    List<Node> subNodes = null;
    if (groupXPath != null && !groupXPath.isEmpty()) {
        if (node.selectSingleNode(groupXPath) != null) {
            subNodes = node.selectSingleNode(groupXPath).selectNodes(propertyXPath);
        }
    } else {
        subNodes = node.selectNodes(propertyXPath);
    }

    if (subNodes != null) {
        for (Node subNode : subNodes) {
            PropertyPropertyElement pe = (PropertyPropertyElement) pec.createAndAdd();
            pe.setValueOfName(XMLReadUtils.valueOf("./name", subNode));
            pe.setValueOfValue(XMLReadUtils.valueOf("./value", subNode));
            pe.setValueOfDescription(XMLReadUtils.valueOf("./description", subNode));
        }
    }
}

From source file:io.mashin.oep.hpdl.XMLReadUtils.java

License:Open Source License

private static void initPropertyPropertyElementFrom(PropertyPropertyElement ppe, Node node) {
    String propName = "";
    String propValue = "";
    String propDescription = "";

    Node n = node.selectSingleNode("name");
    if (n != null) {
        propName = n.getText();//from   w ww  . j  av a 2s.c  om
    }

    n = node.selectSingleNode("value");
    if (n != null) {
        propValue = n.getText();
    }

    n = node.selectSingleNode("description");
    if (n != null) {
        propDescription = n.getText();
    }

    ppe.setValueOfName(propName);
    ppe.setValueOfValue(propValue);
    ppe.setValueOfDescription(propDescription);
}

From source file:io.mashin.oep.hpdl.XMLReadUtils.java

License:Open Source License

public static void initGlobalPropertyFrom(GlobalPropertyElement gpe, Node node, String xpath) {
    Node globalNode = node.selectSingleNode(xpath);
    if (globalNode != null) {
        initTextPropertyFrom(gpe.jobtracker, globalNode, "./job-tracker");
        initTextPropertyFrom(gpe.namenode, globalNode, "./name-node");
        initTextCollectionFrom(gpe.jobxml, globalNode, "./job-xml");
        initPropertiesCollectionFrom(gpe.configuration, globalNode, "./configuration", "./property");
    }//  w ww . j  a va2 s .com
}

From source file:io.mashin.oep.hpdl.XMLReadUtils.java

License:Open Source License

public static void initPreparePropertyFrom(PreparePropertyElement ppe, Node node, String xpath) {
    Node prepareNode = node.selectSingleNode(xpath);
    if (prepareNode != null) {
        initTextCollectionFromAttribute(ppe.delete, prepareNode, "./delete", "@path");
        initTextCollectionFromAttribute(ppe.mkdir, prepareNode, "./mkdir", "@path");
    }/*  w w  w. j  a v  a 2 s .  co m*/
}

From source file:io.mashin.oep.hpdl.XMLReadUtils.java

License:Open Source License

public static void initCredentialsCollectionFrom(PropertyElementCollection pec, Node node, String groupXPath,
        String childXPath) {/*from   ww  w .j a v a2 s . com*/
    Node groupNode = node.selectSingleNode(groupXPath);
    if (groupNode != null) {
        @SuppressWarnings("unchecked")
        List<Node> subNodes = groupNode.selectNodes(childXPath);
        if (subNodes != null) {
            for (Node subNode : subNodes) {
                CredentialPropertyElement cpe = (CredentialPropertyElement) pec.createAndAdd();
                cpe.setValueOfName(valueOf("@name", subNode));
                cpe.setValueOfType(valueOf("@type", subNode));
                initPropertiesCollectionFrom(cpe.credential, subNode, null, "./property");
            }
        }
    }
}