another set of patches from Anthony Jones for copy operations cleanup and

* valid.c tree.c entities.c: another set of patches from
  Anthony Jones for copy operations cleanup and robustness
Daniel
diff --git a/tree.c b/tree.c
index 241bd08..50a7e1e 100644
--- a/tree.c
+++ b/tree.c
@@ -1824,11 +1824,13 @@
     if (tree->type == XML_ENTITY_DECL)
 	return;
     if (tree->doc != doc) {
-	prop = tree->properties;
-	while (prop != NULL) {
-	    prop->doc = doc;
-	    xmlSetListDoc(prop->children, doc);
-	    prop = prop->next;
+	if(tree->type == XML_ELEMENT_NODE) {
+	    prop = tree->properties;
+	    while (prop != NULL) {
+		prop->doc = doc;
+		xmlSetListDoc(prop->children, doc);
+		prop = prop->next;
+	    }
 	}
 	if (tree->children != NULL)
 	    xmlSetListDoc(tree->children, doc);