>     Is there any support in Xerces API to get the XPath value for a node
> in a XML document?

There's been lots of discussion about providing an XPath generating utility
function, but I don't think anyone has ever gotten around to contributing
one. The basic logic I'd try would be something like the following
(untested!) pseudocode:

     buffer=""
     while(thisnode.getNodeType()!=DOCUMENT_NODE)
     {
          count=0;
          name=thisnode.getNodeName();
          for(prevsib=thisnode.getPreviousSibling();
              prevsib!=null;
              prevsib=prevsib.getPreviousSibling())
          {
               if(name.equals(prevsib.getNodeName())
                    ++count;
          }
          buffer="/"+name+"["+count+"]"+buffer;
     }

As sketched that only works for elements; it'd have to be refined to deal
with starting from other kinds of nodes. This sketch isn't namespace-aware;
that'd also have to be fixed. And of course it assumes the node is in the
main document tree; if it's part of an orphaned subtree or a
DocumentFragment tree, you'd have to decide how best to represent that.

A few days's hacking ought to be all that's needed, though. Good project
for someone who's reasonably familiar with the DOM and wants to become more
familiar with XPath to tackle and contribute to Xalan...


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to