Bug 337020
diff --git a/plugins/org.eclipse.actf.model.dom.html/src/org/eclipse/actf/model/internal/dom/sgml/impl/SGMLDocument.java b/plugins/org.eclipse.actf.model.dom.html/src/org/eclipse/actf/model/internal/dom/sgml/impl/SGMLDocument.java
index 46aac62..acd3ac1 100644
--- a/plugins/org.eclipse.actf.model.dom.html/src/org/eclipse/actf/model/internal/dom/sgml/impl/SGMLDocument.java
+++ b/plugins/org.eclipse.actf.model.dom.html/src/org/eclipse/actf/model/internal/dom/sgml/impl/SGMLDocument.java
@@ -17,6 +17,7 @@
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Hashtable;
+import java.util.List;
 
 import org.eclipse.actf.model.internal.dom.sgml.ISGMLDocument;
 import org.w3c.dom.Attr;
@@ -586,12 +587,12 @@
 	public Element getElementById(String elementID) {
 		// replaced for performance reason @2009/06/25 by dsato@jp.ibm.com
 		if (documentElement instanceof SGMLElement) {
-			HashMap<String, WeakReference<Element>> map = SGMLParentNode.getIdMap(this);
-			WeakReference<Element> wr = map.get(elementID);
-			if (wr == null) {
+			HashMap<String, List<WeakReference<Element>>> map = SGMLParentNode.getIdMap(this);
+			List<WeakReference<Element>> list = map.get(elementID);
+			if (list == null) {
 				return null;
 			}
-			return wr.get();
+			return list.get(0).get();
 		}
 		return null;
 		// very slow
diff --git a/plugins/org.eclipse.actf.model.dom.html/src/org/eclipse/actf/model/internal/dom/sgml/impl/SGMLParentNode.java b/plugins/org.eclipse.actf.model.dom.html/src/org/eclipse/actf/model/internal/dom/sgml/impl/SGMLParentNode.java
index 410a3d2..90d3586 100644
--- a/plugins/org.eclipse.actf.model.dom.html/src/org/eclipse/actf/model/internal/dom/sgml/impl/SGMLParentNode.java
+++ b/plugins/org.eclipse.actf.model.dom.html/src/org/eclipse/actf/model/internal/dom/sgml/impl/SGMLParentNode.java
@@ -14,6 +14,8 @@
 import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 import java.util.WeakHashMap;
 
 import org.w3c.dom.DOMException;
@@ -347,9 +349,16 @@
 	
 	private void removeNodeForOptimization(Element element) {
 		String id = element.getAttribute("id");
-		HashMap<String,WeakReference<Element>> idMap = getIdMap(ownerDocument);
+		HashMap<String,List<WeakReference<Element>>> idMap = getIdMap(ownerDocument);
 		if (id != null) {
-			idMap.remove(id);
+			List<WeakReference<Element>> list = idMap.get(id);
+			if (list != null) {
+				for(Iterator<WeakReference<Element>> i = list.iterator(); i.hasNext();) {
+					if (i.next().get() == element) {
+						i.remove();
+					}
+				}
+			}
 		}
 
 		String name = element.getNodeName().toLowerCase();
@@ -429,19 +438,33 @@
 	
 	protected void processIdForOptimization(Element element) {
 		String id = element.getAttribute("id");
-		HashMap<String,WeakReference<Element>> idMap = getIdMap(ownerDocument);
+		HashMap<String,List<WeakReference<Element>>> idMap = getIdMap(ownerDocument);
 		
 		for (String key: idMap.keySet()) {
-			if (idMap.get(key).get() == element) {
-				idMap.remove(key);
-				break;
+			List<WeakReference<Element>> list = idMap.get(key);
+			if (list != null) {
+				for(Iterator<WeakReference<Element>> i = list.iterator(); i.hasNext();) {
+					if (i.next().get() == element) {
+						i.remove();
+					}
+				}
 			}
 		}
 		
 		if (id != null && id.length() > 0) {
-			WeakReference<Element> wr = idMap.get(id);
-			if (wr == null) {
-				idMap.put(id, wr = new WeakReference<Element>(element));
+			List<WeakReference<Element>> list = idMap.get(id);
+			if (list == null) {
+				list = new ArrayList<WeakReference<Element>>();
+				idMap.put(id, list);
+			}
+			boolean flag = true;
+			for(Iterator<WeakReference<Element>> i = list.iterator(); i.hasNext();) {
+				if (i.next().get() == element) {
+					flag = false;
+				}
+			}
+			if (flag) {
+				list.add(new WeakReference<Element>(element));
 			}
 		}
 	}
@@ -490,12 +513,12 @@
 		return nodeList;
 	}
 	
-	private static WeakHashMap<Document,HashMap<String,WeakReference<Element>>> documentIdMap = new WeakHashMap<Document,HashMap<String,WeakReference<Element>>>();
+	private static WeakHashMap<Document,HashMap<String,List<WeakReference<Element>>>> documentIdMap = new WeakHashMap<Document,HashMap<String,List<WeakReference<Element>>>>();
 	
-	protected static HashMap<String,WeakReference<Element>> getIdMap(Document doc) {
-		HashMap<String,WeakReference<Element>> idMap = documentIdMap.get(doc);
+	protected static HashMap<String,List<WeakReference<Element>>> getIdMap(Document doc) {
+		HashMap<String,List<WeakReference<Element>>> idMap = documentIdMap.get(doc);
 		if (idMap == null) {
-			idMap = new HashMap<String,WeakReference<Element>>();
+			idMap = new HashMap<String,List<WeakReference<Element>>>();
 			documentIdMap.put(doc, idMap);
 		}
 		return idMap;