avoid returning default namespace when searching from an attribute reverse

* tree.c: avoid returning default namespace when searching
  from an attribute
* entities.c xmlwriter.c: reverse xmlEncodeSpecialChars() behaviour
  back to escaping " since the normal serialization routines do not
  use it anymore, should close bug #134477 . Tried to make
  the writer avoid it too but it didn't work.
Daniel
diff --git a/tree.c b/tree.c
index 08ac731..4d18cff 100644
--- a/tree.c
+++ b/tree.c
@@ -5481,6 +5481,7 @@
 {
     xmlNsPtr cur;
     xmlNodePtr orig = node;
+    int is_attr;
 
     if ((node == NULL) || (href == NULL))
         return (NULL);
@@ -5524,6 +5525,7 @@
         }
         return (doc->oldNs);
     }
+    is_attr = (node->type == XML_ATTRIBUTE_NODE);
     while (node != NULL) {
         if ((node->type == XML_ENTITY_REF_NODE) ||
             (node->type == XML_ENTITY_NODE) ||
@@ -5534,7 +5536,8 @@
             while (cur != NULL) {
                 if ((cur->href != NULL) && (href != NULL) &&
                     (xmlStrEqual(cur->href, href))) {
-		    if (xmlNsInScope(doc, orig, node, cur->href) == 1)
+		    if (((!is_attr) || (cur->prefix != NULL)) &&
+		        (xmlNsInScope(doc, orig, node, cur->href) == 1))
 			return (cur);
                 }
                 cur = cur->next;
@@ -5544,7 +5547,8 @@
                 if (cur != NULL) {
                     if ((cur->href != NULL) && (href != NULL) &&
                         (xmlStrEqual(cur->href, href))) {
-		        if (xmlNsInScope(doc, orig, node, cur->href) == 1)
+			if (((!is_attr) || (cur->prefix != NULL)) &&
+		            (xmlNsInScope(doc, orig, node, cur->href) == 1))
 			    return (cur);
                     }
                 }