Hi, Age,

You're welcome, I'm glad something I did is of use to others. To understand why it works, imagine that the use element is like a phantom svg tree hanging off your DOM tree. If you just climb the use element you'll eventually hit an empty svg, like the hook on a tree ornament! Just comment out the .getCSSParent() call, you'll see. That's the imported root, I think of it as imported from <defs>. So, if you hit an imported svg, you have to step off to the branch of the DOM tree to continue climbing, and the Batik folks have given us this method for doing so. I suggest reading the W3C spec on <use> elements very closely - I found it somewhat ambiguous.

Your suggestion regarding the null value is well taken, but the behavior is a design choice (maybe not the best) for consistency with DOMTreeWalker navigation behavior. Sometimes my code starts from a group just under the document element and never sees a <use> element.

Dan

Age Bosma wrote:
2009/1/29 Dan Slater <[email protected]>:

Hi, Age,

Never mind the filter.  This will get you where you want to go...supply your
click target, and modify it to break at the use element - you'll see you can
access the id:

  public static SVGElement returnNextDOMEltUp(SVGElement svgElt) {
      Node n = svgElt;
      String name = "start";

      while (!name.equals("g")) {
              if (n instanceof SVGOMCSSImportedElementRoot){
                  n=((SVGOMCSSImportedElementRoot)n).getCSSParentElement();
              } else    {
                  n = n.getParentNode();
                  if (n instanceof SVGOMDocument) return null;
              }
              if (n instanceof SVGElement) {
                  showIdAndNodeName(n);
              }
              name = n.getNodeName();
      }
            if (n instanceof SVGElement) {
              svgElt = (SVGElement)n;
          } else svgElt = null;
            return svgElt;
  }


Many thanks for the help Dan, with some minor alterations it works
like a charm. I still don't completely understand why it has to be
done this way but it works.

One alteration worth mentioning is changing the 'if (n instanceof
SVGOMDocument)' statement to return the original input element
'svgElt' instead of null. This will deal with referenced elements not
located in a 'defs' element/section.

Age

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to