JPalo: How can I find an element by its attribute value?

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • JPalo: How can I find an element by its attribute value?

      Assuming every Element in a given Dimension has an attribute with a unique value, how can I quickly find an element, given only an attribute value? The only way I can see in jpalo to do this is to walk each element:

      Source Code

      1. // Looking for an element with a "uniqueId" attribute of "1234":
      2. Attribute attr = dimension.getAttributeByName("uniqueId");
      3. for (Element e : dimension.getElements()) {
      4. String attrValue = (String)e.getAttributeValue(attr);
      5. if ("1234".equals(attrValue))
      6. return e; // found it!
      7. }
      8. return null; // did not find it :(


      This is hugely inefficient, especially if there are thousands of elements in a given dimension. Isn't there some way to just find an Element by specifying the attribute name and value that you're looking for?
    • Never mind, I solved this problem in the ETL by creating a second dimension whose element values are the uniqueId attributes from the first dimension, and who have an attribute with the name of the element in the first dimension. This way I can very quickly look up an element in one dimension given only an attribute value which corresponds to an element value in the other dimension.