- 
                Notifications
    You must be signed in to change notification settings 
- Fork 92
Open
Description
Hi, i'm writing a Scala library to add a functional layer to this library.
In my library i've defined a rule to edit the xml document.
This rule contains:
- a function NodeSeq => NodeSeq called Zoom
- an action to apply to the target(target = Zoom applied to the whole document)
With this rule instance i create a standard RewriteRule that will be applied to the whole document using a RuleTransformer.
The code is something like this:
val document : NodeSeq = ???
val rule : XmlRule = ???
val target : NodeSeq = rule.zoom(document)
val rwr = new RewriteRule {
  override def transform(ns: Seq[Node]): Seq[Node] = {
    if(ns == target)
      rule.action(target)
    else 
      ns 
  }
}Problem
The problem is: when the document has nodes with the same values ns == target returns true multiple times, also if that node doesn't descends from the same parent.
Question
There is a way to obtain an unique id for each node ? If not, it should be a valid proposal generating an unique id during the node instantiation and keep it as node field ?
abstract class Node {
  private lazy val uuid : UUID = UUID.randomUUID() //or something else
  def sameInstance(that: Node) : Boolean = {
    this.equals(that) && this.uuid.equals(that.uuid)
  }
} 
val n1 : Node = <Node />
val n2 : Node = <Node />
n1.sameInstance(n2) //falseMetadata
Metadata
Assignees
Labels
No labels