AXISCPP-1090 Wrong namespace being used (part 2)
diff --git a/src/wsdl/org/apache/axis/wsdl/wsdl2ws/c/BeanParamWriter.java b/src/wsdl/org/apache/axis/wsdl/wsdl2ws/c/BeanParamWriter.java
index b0156d9..d4cb21d 100644
--- a/src/wsdl/org/apache/axis/wsdl/wsdl2ws/c/BeanParamWriter.java
+++ b/src/wsdl/org/apache/axis/wsdl/wsdl2ws/c/BeanParamWriter.java
@@ -232,7 +232,14 @@
         {
             String namespace = "NULL";
             if (attribs[i].getNsQualified())
+            {
                 namespace = "Axis_URI_" + c_classname;
+                
+                // Elements can reference other elements in different schema...need to handle.
+                QName elementName = attribs[i].getElementName();
+                if (elementName != null)
+                   namespace = "\"" + elementName.getNamespaceURI() + "\"";
+            }
             
             // if the attribute is a choice following should do
             boolean ifCheckPrinted = false;
@@ -325,15 +332,6 @@
             else
             {
                 //if complex type
-                namespace = type.getName().getNamespaceURI();
-                
-                String elm        = attribs[i].getParamNameAsSOAPString();
-                QName elementName = attribs[i].getElementName();
-                if (elementName != null)
-                   namespace = elementName.getNamespaceURI();
-                
-                if (attribs[i].isReference())
-                    elm = attribs[i].getTypeName();
                 
                 String tab = "";
                 if (ifCheckPrinted)
@@ -344,8 +342,17 @@
                     c_writer.write("\tif (param->" + attribs[i].getParamNameAsMember() + " != NULL)\n\t{\n\t");
                 }
                 
+                String elm = attribs[i].getParamNameAsSOAPString();
+                if (attribs[i].isReference())
+                    elm = attribs[i].getTypeName();
+                
                 if (attribs[i].getNsQualified())
                 {
+                    namespace = type.getName().getNamespaceURI();
+                    QName elementName = attribs[i].getElementName();
+                    if (elementName != null)
+                       namespace = elementName.getNamespaceURI();
+                    
                     c_writer.write("\tsPrefix = axiscSoapSerializerGetNamespacePrefix(pSZ, \"" + namespace + "\", &blnIsNewSubElemPrefix);\n");
                     c_writer.write(tab + "\taxiscSoapSerializerSerialize(pSZ, \"<\", sPrefix, \":\", \"" + elm + "\", 0);\n");
                     c_writer.write(tab + "\tif (blnIsNewSubElemPrefix)\n");
diff --git a/src/wsdl/org/apache/axis/wsdl/wsdl2ws/cpp/BeanParamWriter.java b/src/wsdl/org/apache/axis/wsdl/wsdl2ws/cpp/BeanParamWriter.java
index 4bc6ec7..02a3180 100644
--- a/src/wsdl/org/apache/axis/wsdl/wsdl2ws/cpp/BeanParamWriter.java
+++ b/src/wsdl/org/apache/axis/wsdl/wsdl2ws/cpp/BeanParamWriter.java
@@ -445,7 +445,14 @@
         {
             String namespace = "NULL";
             if (attribs[i].getNsQualified())
+            {
                 namespace = "Axis_URI_" + c_classname;
+                
+                // Elements can reference other elements in different schema...need to handle.
+                QName elementName = attribs[i].getElementName();
+                if (elementName != null)
+                   namespace = "\"" + elementName.getNamespaceURI() + "\"";
+            }
             
             // if the attribute is a choice following should do
             boolean ifCheckPrinted = false;
@@ -537,15 +544,6 @@
             else
             {
                 //if complex type
-                namespace = type.getName().getNamespaceURI();
-                
-                String elm = attribs[i].getParamNameAsSOAPString();
-                QName elementName = attribs[i].getElementName();
-                if (elementName != null)
-                   namespace = elementName.getNamespaceURI();
-
-                if (attribs[i].isReference())
-                    elm = attribs[i].getTypeName();
                 
                 String tab = "";
                 if (ifCheckPrinted)
@@ -556,8 +554,17 @@
                     c_writer.write("\tif (param->" + attribs[i].getParamNameAsMember() + " != NULL)\n\t{\n\t");
                 }
                 
+                String elm = attribs[i].getParamNameAsSOAPString();
+                if (attribs[i].isReference())
+                    elm = attribs[i].getTypeName();
+
                 if (attribs[i].getNsQualified())
                 {
+                    namespace = type.getName().getNamespaceURI();
+                    QName elementName = attribs[i].getElementName();
+                    if (elementName != null)
+                       namespace = elementName.getNamespaceURI();
+
                     c_writer.write("\tsPrefix = pSZ->getNamespacePrefix(\"" + namespace + "\", blnIsNewSubElemPrefix);\n");
                     c_writer.write(tab + "\tpSZ->serialize(\"<\", sPrefix, \":\", \"" + elm + "\", 0);\n");
                     c_writer.write(tab + "\tif (blnIsNewSubElemPrefix)\n");