Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Developers

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-05-2005, 02:37 PM
Senior Member
 
Posts: 51
Default AjxUtil.xmlToJs can't handle namespaces

The AjxUtil.xmlToJs method can't handle namespaces in attribute tags.

The response of a SOAP request:
Code:
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <env:Body>
    <n1:FindAllProductsResponse xmlns:n1="urn:ActionWebService" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <return n2:arrayType="xsd:int[4]" xmlns:n2="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="n2:Array">
        <item>
          1
        </item>
        <item>
          2
        </item>
        <item>
          3
        </item>
        <item>
          4
        </item>
      </return>
    </n1:FindAllProductsResponse>
  </env:Body>
</env:Envelope>
The result after it is been processed by AjxUtil.xmlToJs (I stripped the whitespaces where I also are having problems with):
Code:
{
	Body:{
		FindAllProductsResponse: {
			xmlns:n1:"urn:ActionWebService",
			env:encodingStyle: "http:\/\/schemas.xmlsoap.org\/soap\/encoding\/",
			return:{
				n2:arrayType:"xsd:int[4]",
				xmlns:n2:"http:\/\/schemas.xmlsoap.org\/soap\/encoding\/",
				xsi:type:"n2:Array",
				"",
				item:{
					"1"
				},
				item:{
					"2"
				},
				item:{
					"3"
				},
				item:{
					"4"
				}
			}
		}
	}
}
If you use the eval function on this then it obviously brakes on xmlns:n1 and so on.

I wrote a little fix:
Code:
AjxUtil.xmlToJs =
function(node, omitName) {

	if (node.nodeType == AjxUtil.TEXT_NODE)
		return ['"', node.data, '"'].join("");

	var name = node.name ? node.name : node.localName;
	if (node.nodeType == AjxUtil.ELEMENT_NODE) {
		var text = omitName ? "{" : [name, ":{"].join("");
		var needComma = false;	
		if (node.attributes ) {
			for (var i = 0; i < node.attributes.length; i++) {
				var attr = node.attributes[i];
				if (attr.name == "xmlns") continue;
				if (needComma) text += ",";
				var value = AjxUtil.isNumeric(attr.value) ? attr.value : AjxUtil.jsEncode(attr.value);
				var attr_name = attr.name
				var indexdblp = attr_name.indexOf(":")
				if(indexdblp != -1 ) attr_name = attr_name.substr(indexdblp+1)

				text = [text, attr_name, ':', value].join("");
				needComma = true;
			}
		}
		if (node.hasChildNodes()) {
			
			var cnodes = new Object();
			var hasChild = false;
			for (var i = 0; i < node.childNodes.length; i++) {
				var child = node.childNodes[i];
				var cname = child.name ? child.name : child.localName;
	
				var isAttr = AjxUtil.NODE_IS_ATTR[cname] || 
							 (name == "content" && parent.name == "note");
							 
				if (isAttr) {
					if (needComma) text += ",";
					text = [text, cname, ':', AjxUtil.jsEncode(child.textContent)].join("");
					needComma = true;
				} else {
					if (!cnodes[cname])
						cnodes[cname] = new Array();
					cnodes[cname].push(child);
					hasChild = true;
				}
			}
			if (hasChild && needComma) {text += ","; needComma = false;}
			for (var cname in cnodes) {
				
				if (needComma) {
					text += ",";
					needComma = false;
				}
				var repeats = AjxUtil.NODE_REPEATS[cname] ||
							  (cname == "mp" && name == "mp");
				if (repeats) text += cname + ":[";
				var clist = cnodes[cname];
				for (var i = 0; i < clist.length; i++) {
					if (needComma) text += ",";
					text += AjxUtil.xmlToJs(clist[i], repeats);
					needComma = true;
				}
				if (repeats) text += "]";
			}
		}
		text += "}";
	}

	return text;
}
Somewhere in the code there are the lines:
var indexdblp = attr_name.indexOf(":")
if(indexdblp != -1 ) attr_name = attr_name.substr(indexdblp+1)

text = [text, attr_name, ':', value].join("");

They take care of the namespaces by removing them.
Reply With Quote
  #2 (permalink)  
Old 11-06-2005, 07:48 PM
Member
 
Posts: 14
Default

I created Web Services in Ms.Net and the result return as below:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<getMasterFilesResponse content="[{&quot;IdentityID&quot;:1,&quot;Code&quot;:&quot;S LS&quot;,&quot;MyName&quot;:&quot;Sales Invoice&quot;},{&quot;IdentityID&quot;:2,&quot;Cod e&quot;:&quot;PYM&quot;,&quot;MyName&quot;:&quot;P ayment Invoice&quot;}]" xmlns="http://www.profrtgroup.com/webservices/" />
</soap:Body>
</soap:Envelope>

it failed to create xmldoc from the above message.
Then i remove <?xml version="1.0" encoding="utf-8"?>, it success....

This occurs only in IE, Firefox is fine.

Help please...
Reply With Quote
  #3 (permalink)  
Old 11-06-2005, 11:50 PM
Senior Member
 
Posts: 51
Default

What kind of error do you get when you try with the header?
Reply With Quote
  #4 (permalink)  
Old 11-07-2005, 12:37 AM
Member
 
Posts: 14
Default

This will not cause an error from CreateXmlFromString
But error occurred in _check function.

the doc will retrun with 2 childnodes...
one for <?xml .... ?>
and another one for <soap:Envelope ....>

_check function will check for only valid return is only one childnode for doc.
Reply With Quote
  #5 (permalink)  
Old 11-07-2005, 01:03 AM
Senior Member
 
Posts: 51
Default Whitespaces

I also had problems with the _check method. Because the AJAX xml methods donīt ignore whitespaces there are more elements in the xml document then _check expects. I already opend a tread about that problem.

Maybe you can right a fix for the problem and share the code with us.
Reply With Quote
  #6 (permalink)  
Old 11-07-2005, 10:58 PM
Member
 
Posts: 14
Default

The main issue for me is the problem occurs only in IE.
Reply With Quote
  #7 (permalink)  
Old 11-08-2005, 10:41 AM
Senior Member
 
Posts: 51
Default New thread

Somebody opend a new thread with the same problem (or is it?). See AjxSoapDoc bug under IE6 only for your answer.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.