From 0064ab3fcb2626035fe45b3897764c25d8b437bb Mon Sep 17 00:00:00 2001
From: Martin Stjernholm <mast@lysator.liu.se>
Date: Thu, 2 Oct 2008 00:58:53 +0200
Subject: [PATCH] Don't require every element to have an id in
 get_element_by_id.

Rev: lib/modules/Parser.pmod/XML.pmod/Tree.pmod:1.73
---
 lib/modules/Parser.pmod/XML.pmod/Tree.pmod | 28 ++++++++++++----------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/lib/modules/Parser.pmod/XML.pmod/Tree.pmod b/lib/modules/Parser.pmod/XML.pmod/Tree.pmod
index bd65f2ad8c..dc7ddb26ec 100644
--- a/lib/modules/Parser.pmod/XML.pmod/Tree.pmod
+++ b/lib/modules/Parser.pmod/XML.pmod/Tree.pmod
@@ -1,7 +1,7 @@
 #pike __REAL_VERSION__
 
 /*
- * $Id: Tree.pmod,v 1.72 2008/06/28 16:36:55 nilsson Exp $
+ * $Id: Tree.pmod,v 1.73 2008/10/01 22:58:53 mast Exp $
  *
  */
 
@@ -1774,13 +1774,14 @@ class SimpleRootNode
       walk_preorder(lambda(SimpleNode node,
 			   mapping(string:SimpleElementNode) new_lookup) {
 		      if (node->get_node_type() != XML_ELEMENT) return 0;
-		      string id = node->get_attributes()->id;
-		      if (new_lookup[id]) {
-			error("Multiple nodes with the same id "
-			      "(id: %O, nodes: %O, %O)\n",
-			      id, new_lookup[id], node);
+		      if (string id = node->get_attributes()->id) {
+			if (new_lookup[id]) {
+			  error("Multiple nodes with the same id "
+				"(id: %O, nodes: %O, %O)\n",
+				id, new_lookup[id], node);
+			}
+			new_lookup[id] = node;
 		      }
-		      new_lookup[id] = node;
 		      return 0;
 		    }, new_lookup);
       node_ids = new_lookup;
@@ -1995,13 +1996,14 @@ class RootNode
       walk_preorder(lambda(SimpleNode node,
 			   mapping(string:ElementNode) new_lookup) {
 		      if (node->get_node_type() != XML_ELEMENT) return 0;
-		      string id = node->get_attributes()->id;
-		      if (new_lookup[id]) {
-			error("Multiple nodes with the same id "
-			      "(id: %O, nodes: %O, %O)\n",
-			      id, new_lookup[id], node);
+		      if (string id = node->get_attributes()->id) {
+			if (new_lookup[id]) {
+			  error("Multiple nodes with the same id "
+				"(id: %O, nodes: %O, %O)\n",
+				id, new_lookup[id], node);
+			}
+			new_lookup[id] = node;
 		      }
-		      new_lookup[id] = node;
 		      return 0;
 		    }, new_lookup);
       node_ids = new_lookup;
-- 
GitLab