3 ** pz2.js - pazpar2's javascript client library.
6 //since explorer is flawed
8 window.Node = new Object();
10 Node.ATTRIBUTE_NODE = 2;
12 Node.CDATA_SECTION_NODE = 4;
13 Node.ENTITY_REFERENCE_NODE = 5;
15 Node.PROCESSING_INSTRUCTION_NODE = 7;
16 Node.COMMENT_NODE = 8;
17 Node.DOCUMENT_NODE = 9;
18 Node.DOCUMENT_TYPE_NODE = 10;
19 Node.DOCUMENT_FRAGMENT_NODE = 11;
20 Node.NOTATION_NODE = 12;
23 // prevent execution of more than once
24 if(typeof window.pz2 == "undefined") {
25 window.undefined = window.undefined;
27 var pz2 = function ( paramArray )
30 // at least one callback required
32 throw new Error("Pz2.js: Array with parameters has to be suplied.");
34 //supported pazpar2's protocol version
35 this.suppProtoVer = '1';
36 if (typeof paramArray.pazpar2path != "undefined")
37 this.pz2String = paramArray.pazpar2path;
39 this.pz2String = "/pazpar2/search.pz2";
40 this.useSessions = true;
42 this.stylesheet = paramArray.detailstylesheet || null;
43 //load stylesheet if required in async mode
44 if( this.stylesheet ) {
46 var request = new pzHttpRequest( this.stylesheet );
47 request.get( {}, function ( doc ) { context.xslDoc = doc; } );
50 this.errorHandler = paramArray.errorhandler || null;
51 this.showResponseType = paramArray.showResponseType || "xml";
54 this.initCallback = paramArray.oninit || null;
55 this.statCallback = paramArray.onstat || null;
56 this.showCallback = paramArray.onshow || null;
57 this.termlistCallback = paramArray.onterm || null;
58 this.recordCallback = paramArray.onrecord || null;
59 this.bytargetCallback = paramArray.onbytarget || null;
60 this.resetCallback = paramArray.onreset || null;
63 this.termKeys = paramArray.termlist || "subject";
65 // some configurational stuff
66 this.keepAlive = 50000;
68 if ( paramArray.keepAlive < this.keepAlive )
69 this.keepAlive = paramArray.keepAlive;
71 this.sessionID = null;
72 this.serviceId = paramArray.serviceId || null;
73 this.initStatusOK = false;
74 this.pingStatusOK = false;
75 this.searchStatusOK = false;
78 this.currentSort = "relevance";
81 this.currentStart = 0;
84 // last full record retrieved
85 this.currRecID = null;
88 this.currQuery = null;
90 //current raw record offset
91 this.currRecOffset = null;
94 this.pingTimer = null;
95 this.statTime = paramArray.stattime || 1000;
96 this.statTimer = null;
97 this.termTime = paramArray.termtime || 1000;
98 this.termTimer = null;
99 this.showTime = paramArray.showtime || 1000;
100 this.showTimer = null;
101 this.showFastCount = 4;
102 this.bytargetTime = paramArray.bytargettime || 1000;
103 this.bytargetTimer = null;
104 this.recordTime = paramArray.recordtime || 500;
105 this.recordTimer = null;
107 // counters for each command and applied delay
108 this.dumpFactor = 500;
109 this.showCounter = 0;
110 this.termCounter = 0;
111 this.statCounter = 0;
112 this.bytargetCounter = 0;
113 this.recordCounter = 0;
115 // active clients, updated by stat and show
116 // might be an issue since bytarget will poll accordingly
117 this.activeClients = 1;
119 // if in proxy mode no need to init
120 if (paramArray.usesessions != undefined) {
121 this.useSessions = paramArray.usesessions;
122 this.initStatusOK = true;
124 // else, auto init session or wait for a user init?
125 if (this.useSessions && paramArray.autoInit !== false) {
126 this.init(this.sessionId, this.serviceId);
132 //error handler for async error throws
133 throwError: function (errMsg, errCode)
135 var err = new Error(errMsg);
136 if (errCode) err.code = errCode;
138 if (this.errorHandler) {
139 this.errorHandler(err);
146 // stop activity by clearing tiemouts
149 clearTimeout(this.statTimer);
150 clearTimeout(this.showTimer);
151 clearTimeout(this.termTimer);
152 clearTimeout(this.bytargetTimer);
155 // reset status variables
158 if ( this.useSessions ) {
159 this.sessionID = null;
160 this.initStatusOK = false;
161 this.pingStatusOK = false;
162 clearTimeout(this.pingTimer);
164 this.searchStatusOK = false;
167 if ( this.resetCallback )
168 this.resetCallback();
171 init: function (sessionId, serviceId)
175 // session id as a param
176 if (sessionId && this.useSessions ) {
177 this.initStatusOK = true;
178 this.sessionID = sessionId;
180 // old school direct pazpar2 init
181 } else if (this.useSessions) {
183 var request = new pzHttpRequest(this.pz2String, this.errorHandler);
184 var opts = {'command' : 'init'};
185 if (serviceId) opts.service = serviceId;
189 if ( data.getElementsByTagName("status")[0]
190 .childNodes[0].nodeValue == "OK" ) {
191 if ( data.getElementsByTagName("protocol")[0]
192 .childNodes[0].nodeValue
193 != context.suppProtoVer )
195 "Server's protocol not supported by the client"
197 context.initStatusOK = true;
199 data.getElementsByTagName("session")[0]
200 .childNodes[0].nodeValue;
208 if ( context.initCallback )
209 context.initCallback();
212 context.throwError('Init failed. Malformed WS resonse.',
216 // when through proxy no need to init
218 this.initStatusOK = true;
221 // no need to ping explicitly
224 // pinging only makes sense when using pazpar2 directly
225 if( !this.initStatusOK || !this.useSessions )
227 'Pz2.js: Ping not allowed (proxy mode) or session not initialized.'
231 clearTimeout(context.pingTimer);
233 var request = new pzHttpRequest(this.pz2String, this.errorHandler);
235 { "command": "ping", "session": this.sessionID, "windowid" : window.name },
237 if ( data.getElementsByTagName("status")[0]
238 .childNodes[0].nodeValue == "OK" ) {
239 context.pingStatusOK = true;
249 context.throwError('Ping failed. Malformed WS resonse.',
254 search: function (query, num, sort, filter, showfrom, addParamsArr)
256 clearTimeout(this.statTimer);
257 clearTimeout(this.showTimer);
258 clearTimeout(this.termTimer);
259 clearTimeout(this.bytargetTimer);
261 this.showCounter = 0;
262 this.termCounter = 0;
263 this.bytargetCounter = 0;
264 this.statCounter = 0;
265 this.activeClients = 1;
268 if( !this.initStatusOK )
269 throw new Error('Pz2.js: session not initialized.');
271 if( query !== undefined )
272 this.currQuery = query;
274 throw new Error("Pz2.js: no query supplied to the search command.");
276 if ( showfrom !== undefined )
277 var start = showfrom;
283 "query": this.currQuery,
284 "session": this.sessionID,
285 "windowid" : window.name
288 if (filter !== undefined)
289 searchParams["filter"] = filter;
291 // copy additional parmeters, do not overwrite
292 if (addParamsArr != undefined) {
293 for (var prop in addParamsArr) {
294 if (!searchParams.hasOwnProperty(prop))
295 searchParams[prop] = addParamsArr[prop];
300 var request = new pzHttpRequest(this.pz2String, this.errorHandler);
304 if ( data.getElementsByTagName("status")[0]
305 .childNodes[0].nodeValue == "OK" ) {
306 context.searchStatusOK = true;
308 context.show(start, num, sort);
309 if (context.statCallback)
311 if (context.termlistCallback)
313 if (context.bytargetCallback)
317 context.throwError('Search failed. Malformed WS resonse.',
324 if( !this.initStatusOK )
325 throw new Error('Pz2.js: session not initialized.');
327 // if called explicitly takes precedence
328 clearTimeout(this.statTimer);
331 var request = new pzHttpRequest(this.pz2String, this.errorHandler);
333 { "command": "stat", "session": this.sessionID, "windowid" : window.name },
335 if ( data.getElementsByTagName("stat") ) {
337 Number( data.getElementsByTagName("activeclients")[0]
338 .childNodes[0].nodeValue );
339 context.activeClients = activeClients;
341 var stat = Element_parseChildNodes(data.documentElement);
343 context.statCounter++;
344 var delay = context.statTime
345 + context.statCounter * context.dumpFactor;
347 if ( activeClients > 0 )
355 context.statCallback(stat);
358 context.throwError('Stat failed. Malformed WS resonse.',
363 show: function(start, num, sort)
365 if( !this.searchStatusOK && this.useSessions )
367 'Pz2.js: show command has to be preceded with a search command.'
370 // if called explicitly takes precedence
371 clearTimeout(this.showTimer);
373 if( sort !== undefined )
374 this.currentSort = sort;
375 if( start !== undefined )
376 this.currentStart = Number( start );
377 if( num !== undefined )
378 this.currentNum = Number( num );
381 var request = new pzHttpRequest(this.pz2String, this.errorHandler);
385 "session": this.sessionID,
386 "start": this.currentStart,
387 "num": this.currentNum,
388 "sort": this.currentSort,
390 "type": this.showResponseType,
391 "windowid" : window.name
393 function(data, type) {
395 var activeClients = 0;
396 if (type === "json") {
398 activeClients = Number(data.activeclients[0]);
399 show.activeclients = activeClients;
400 show.merged = Number(data.merged[0]);
401 show.total = Number(data.total[0]);
402 show.start = Number(data.start[0]);
403 show.num = Number(data.num[0]);
404 show.hits = data.hit;
405 } else if (data.getElementsByTagName("status")[0]
406 .childNodes[0].nodeValue == "OK") {
407 // first parse the status data send along with records
408 // this is strictly bound to the format
410 Number(data.getElementsByTagName("activeclients")[0]
411 .childNodes[0].nodeValue);
413 "activeclients": activeClients,
415 Number( data.getElementsByTagName("merged")[0]
416 .childNodes[0].nodeValue ),
418 Number( data.getElementsByTagName("total")[0]
419 .childNodes[0].nodeValue ),
421 Number( data.getElementsByTagName("start")[0]
422 .childNodes[0].nodeValue ),
424 Number( data.getElementsByTagName("num")[0]
425 .childNodes[0].nodeValue ),
428 // parse all the first-level nodes for all <hit> tags
429 var hits = data.getElementsByTagName("hit");
430 for (i = 0; i < hits.length; i++)
431 show.hits[i] = Element_parseChildNodes(hits[i]);
433 context.throwError('Show failed. Malformed WS resonse.',
436 context.activeClients = activeClients;
437 context.showCounter++;
438 var delay = context.showTime;
439 if (context.showCounter > context.showFastCount)
440 delay += context.showCounter * context.dumpFactor;
441 if ( activeClients > 0 )
442 context.showTimer = setTimeout(
447 context.showCallback(show);
451 record: function(id, offset, syntax, handler)
453 // we may call record with no previous search if in proxy mode
454 if(!this.searchStatusOK && this.useSessions)
456 'Pz2.js: record command has to be preceded with a search command.'
459 if( id !== undefined )
464 "session": this.sessionID,
465 "id": this.currRecID,
466 "windowid" : window.name
469 this.currRecOffset = null;
470 if (offset != undefined) {
471 recordParams["offset"] = offset;
472 this.currRecOffset = offset;
475 if (syntax != undefined)
476 recordParams['syntax'] = syntax;
478 //overwrite default callback id needed
479 var callback = this.recordCallback;
480 var args = undefined;
481 if (handler != undefined) {
482 callback = handler['callback'];
483 args = handler['args'];
487 var request = new pzHttpRequest(this.pz2String, this.errorHandler);
495 if (context.currRecOffset !== null) {
496 record = new Array();
497 record['xmlDoc'] = data;
498 record['offset'] = context.currRecOffset;
499 callback(record, args);
501 } else if ( recordNode =
502 data.getElementsByTagName("record")[0] ) {
503 // if stylesheet was fetched do not parse the response
504 if ( context.xslDoc ) {
505 record = new Array();
506 record['xmlDoc'] = data;
507 record['xslDoc'] = context.xslDoc;
509 recordNode.getElementsByTagName("recid")[0]
510 .firstChild.nodeValue;
513 record = Element_parseChildNodes(recordNode);
516 Number( data.getElementsByTagName("activeclients")[0]
517 .childNodes[0].nodeValue );
518 context.activeClients = activeClients;
519 context.recordCounter++;
520 var delay = context.recordTime + context.recordCounter * context.dumpFactor;
521 if ( activeClients > 0 )
522 context.recordTimer =
525 context.record(id, offset, syntax, handler);
529 callback(record, args);
532 context.throwError('Record failed. Malformed WS resonse.',
540 if( !this.searchStatusOK && this.useSessions )
542 'Pz2.js: termlist command has to be preceded with a search command.'
545 // if called explicitly takes precedence
546 clearTimeout(this.termTimer);
549 var request = new pzHttpRequest(this.pz2String, this.errorHandler);
552 "command": "termlist",
553 "session": this.sessionID,
554 "name": this.termKeys,
555 "windowid" : window.name
558 if ( data.getElementsByTagName("termlist") ) {
560 Number( data.getElementsByTagName("activeclients")[0]
561 .childNodes[0].nodeValue );
562 context.activeClients = activeClients;
563 var termList = { "activeclients": activeClients };
564 var termLists = data.getElementsByTagName("list");
566 for (i = 0; i < termLists.length; i++) {
567 var listName = termLists[i].getAttribute('name');
568 termList[listName] = new Array();
569 var terms = termLists[i].getElementsByTagName('term');
570 //for each term in the list
571 for (j = 0; j < terms.length; j++) {
574 (terms[j].getElementsByTagName("name")[0]
576 ? terms[j].getElementsByTagName("name")[0]
577 .childNodes[0].nodeValue
581 .getElementsByTagName("frequency")[0]
582 .childNodes[0].nodeValue || 'ERROR'
586 terms[j].getElementsByTagName("id");
587 if(terms[j].getElementsByTagName("id").length)
589 termIdNode[0].childNodes[0].nodeValue;
590 termList[listName][j] = term;
594 context.termCounter++;
595 var delay = context.termTime
596 + context.termCounter * context.dumpFactor;
597 if ( activeClients > 0 )
606 context.termlistCallback(termList);
609 context.throwError('Termlist failed. Malformed WS resonse.',
617 if( !this.initStatusOK && this.useSessions )
619 'Pz2.js: bytarget command has to be preceded with a search command.'
622 // no need to continue
623 if( !this.searchStatusOK )
626 // if called explicitly takes precedence
627 clearTimeout(this.bytargetTimer);
630 var request = new pzHttpRequest(this.pz2String, this.errorHandler);
633 "command": "bytarget",
634 "session": this.sessionID,
636 "windowid" : window.name
639 if ( data.getElementsByTagName("status")[0]
640 .childNodes[0].nodeValue == "OK" ) {
641 var targetNodes = data.getElementsByTagName("target");
642 var bytarget = new Array();
643 for ( i = 0; i < targetNodes.length; i++) {
644 bytarget[i] = new Array();
645 for( j = 0; j < targetNodes[i].childNodes.length; j++ ) {
646 if ( targetNodes[i].childNodes[j].nodeType
647 == Node.ELEMENT_NODE ) {
649 targetNodes[i].childNodes[j].nodeName;
651 targetNodes[i].childNodes[j]
652 .firstChild.nodeValue;
653 bytarget[i][nodeName] = nodeText;
656 if (bytarget[i]["state"]=="Client_Disconnected") {
657 bytarget[i]["hits"] = "Error";
658 } else if (bytarget[i]["state"]=="Client_Error") {
659 bytarget[i]["hits"] = "Error";
660 } else if (bytarget[i]["state"]=="Client_Working") {
661 bytarget[i]["hits"] = "...";
663 if (bytarget[i].diagnostic == "1") {
664 bytarget[i].diagnostic = "Permanent system error";
665 } else if (bytarget[i].diagnostic == "2") {
666 bytarget[i].diagnostic = "Temporary system error";
668 var targetsSuggestions = targetNodes[i].getElementsByTagName("suggestions");
669 if (targetsSuggestions != undefined && targetsSuggestions.length>0) {
670 var suggestions = targetsSuggestions[0];
671 bytarget[i]["suggestions"] = Element_parseChildNodes(suggestions);
675 context.bytargetCounter++;
676 var delay = context.bytargetTime
677 + context.bytargetCounter * context.dumpFactor;
678 if ( context.activeClients > 0 )
679 context.bytargetTimer =
687 context.bytargetCallback(bytarget);
690 context.throwError('Bytarget failed. Malformed WS resonse.',
696 // just for testing, probably shouldn't be here
697 showNext: function(page)
699 var step = page || 1;
700 this.show( ( step * this.currentNum ) + this.currentStart );
703 showPrev: function(page)
705 if (this.currentStart == 0 )
707 var step = page || 1;
708 var newStart = this.currentStart - (step * this.currentNum );
709 this.show( newStart > 0 ? newStart : 0 );
712 showPage: function(pageNum)
714 //var page = pageNum || 1;
715 this.show(pageNum * this.currentNum);
720 ********************************************************************************
721 ** AJAX HELPER CLASS ***********************************************************
722 ********************************************************************************
724 var pzHttpRequest = function ( url, errorHandler ) {
725 this.maxUrlLength = 2048;
728 this.errorHandler = errorHandler || null;
730 this.requestHeaders = {};
732 if ( window.XMLHttpRequest ) {
733 this.request = new XMLHttpRequest();
734 } else if ( window.ActiveXObject ) {
736 this.request = new ActiveXObject( 'Msxml2.XMLHTTP' );
738 this.request = new ActiveXObject( 'Microsoft.XMLHTTP' );
744 pzHttpRequest.prototype =
746 safeGet: function ( params, callback )
748 var encodedParams = this.encodeParams(params);
749 var url = this._urlAppendParams(encodedParams);
750 if (url.length >= this.maxUrlLength) {
751 this.requestHeaders["Content-Type"]
752 = "application/x-www-form-urlencoded";
753 this._send( 'POST', this.url, encodedParams, callback );
755 this._send( 'GET', url, '', callback );
759 get: function ( params, callback )
761 this._send( 'GET', this._urlAppendParams(this.encodeParams(params)),
765 post: function ( params, data, callback )
767 this._send( 'POST', this._urlAppendParams(this.encodeParams(params)),
774 this.request.open( 'GET', this.url, this.async );
775 this.request.send('');
776 if ( this.request.status == 200 )
777 return this.request.responseXML;
780 encodeParams: function (params)
784 for (var key in params) {
785 if (params[key] != null) {
786 encoded += sep + key + '=' + encodeURIComponent(params[key]);
793 _send: function ( type, url, data, callback)
796 this.callback = callback;
798 this.request.open( type, url, this.async );
799 for (var key in this.requestHeaders)
800 this.request.setRequestHeader(key, this.requestHeaders[key]);
801 this.request.onreadystatechange = function () {
802 context._handleResponse(url); /// url used ONLY for error reporting
804 this.request.send(data);
807 _urlAppendParams: function (encodedParams)
810 return this.url + "?" + encodedParams;
815 _handleResponse: function (savedUrlForErrorReporting)
817 if ( this.request.readyState == 4 ) {
818 // pick up appplication errors first
820 if (this.request.responseXML &&
821 (errNode = this.request.responseXML.documentElement)
822 && errNode.nodeName == 'error') {
823 var errMsg = errNode.getAttribute("msg");
824 var errCode = errNode.getAttribute("code");
826 if (errNode.childNodes.length)
827 errAddInfo = ': ' + errNode.childNodes[0].nodeValue;
829 var err = new Error(errMsg + errAddInfo);
832 if (this.errorHandler) {
833 this.errorHandler(err);
838 } else if (this.request.status == 200 &&
839 this.request.responseXML == null) {
840 if (this.request.responseText != null) {
844 var text = this.request.responseText;
845 if (typeof window.JSON == "undefined")
846 json = eval("(" + text + ")");
849 json = JSON.parse(text);
852 // Safari: eval will fail as well. Considering trying JSON2 (non-native implementation) instead
853 /* DEBUG only works in mk2-mobile
854 if (document.getElementById("log"))
855 document.getElementById("log").innerHTML = "" + e + " " + length + ": " + text;
858 json = eval("(" + text + ")");
861 /* DEBUG only works in mk2-mobile
862 if (document.getElementById("log"))
863 document.getElementById("log").innerHTML = "" + e + " " + length + ": " + text;
868 this.callback(json, "json");
870 var err = new Error("XML response is empty but no error " +
871 "for " + savedUrlForErrorReporting);
873 if (this.errorHandler) {
874 this.errorHandler(err);
879 } else if (this.request.status == 200) {
880 this.callback(this.request.responseXML);
882 var err = new Error("HTTP response not OK: "
883 + this.request.status + " - "
884 + this.request.statusText );
885 err.code = '00' + this.request.status;
886 if (this.errorHandler) {
887 this.errorHandler(err);
898 ********************************************************************************
899 ** XML HELPER FUNCTIONS ********************************************************
900 ********************************************************************************
905 if ( window.ActiveXObject) {
906 var DOMDoc = document;
908 var DOMDoc = Document.prototype;
911 DOMDoc.newXmlDoc = function ( root )
915 if (document.implementation && document.implementation.createDocument) {
916 doc = document.implementation.createDocument('', root, null);
917 } else if ( window.ActiveXObject ) {
918 doc = new ActiveXObject("MSXML2.DOMDocument");
919 doc.loadXML('<' + root + '/>');
921 throw new Error ('No XML support in this browser');
928 DOMDoc.parseXmlFromString = function ( xmlString )
932 if ( window.DOMParser ) {
933 var parser = new DOMParser();
934 doc = parser.parseFromString( xmlString, "text/xml");
935 } else if ( window.ActiveXObject ) {
936 doc = new ActiveXObject("MSXML2.DOMDocument");
937 doc.loadXML( xmlString );
939 throw new Error ("No XML parsing support in this browser.");
945 DOMDoc.transformToDoc = function (xmlDoc, xslDoc)
947 if ( window.XSLTProcessor ) {
948 var proc = new XSLTProcessor();
949 proc.importStylesheet( xslDoc );
950 return proc.transformToDocument(xmlDoc);
951 } else if ( window.ActiveXObject ) {
952 return document.parseXmlFromString(xmlDoc.transformNode(xslDoc));
954 alert( 'Unable to perform XSLT transformation in this browser' );
960 Element_removeFromDoc = function (DOM_Element)
962 DOM_Element.parentNode.removeChild(DOM_Element);
965 Element_emptyChildren = function (DOM_Element)
967 while( DOM_Element.firstChild ) {
968 DOM_Element.removeChild( DOM_Element.firstChild )
972 Element_appendTransformResult = function ( DOM_Element, xmlDoc, xslDoc )
974 if ( window.XSLTProcessor ) {
975 var proc = new XSLTProcessor();
976 proc.importStylesheet( xslDoc );
978 docFrag = proc.transformToFragment( xmlDoc, DOM_Element.ownerDocument );
979 DOM_Element.appendChild(docFrag);
980 } else if ( window.ActiveXObject ) {
981 DOM_Element.innerHTML = xmlDoc.transformNode( xslDoc );
983 alert( 'Unable to perform XSLT transformation in this browser' );
987 Element_appendTextNode = function (DOM_Element, tagName, textContent )
989 var node = DOM_Element.ownerDocument.createElement(tagName);
990 var text = DOM_Element.ownerDocument.createTextNode(textContent);
992 DOM_Element.appendChild(node);
993 node.appendChild(text);
998 Element_setTextContent = function ( DOM_Element, textContent )
1000 if (typeof DOM_Element.textContent !== "undefined") {
1001 DOM_Element.textContent = textContent;
1002 } else if (typeof DOM_Element.innerText !== "undefined" ) {
1003 DOM_Element.innerText = textContent;
1005 throw new Error("Cannot set text content of the node, no such method.");
1009 Element_getTextContent = function (DOM_Element)
1011 if ( typeof DOM_Element.textContent != 'undefined' ) {
1012 return DOM_Element.textContent;
1013 } else if (typeof DOM_Element.text != 'undefined') {
1014 return DOM_Element.text;
1016 throw new Error("Cannot get text content of the node, no such method.");
1020 Element_parseChildNodes = function (node)
1023 var hasChildElems = false;
1025 if (node.hasChildNodes()) {
1026 var children = node.childNodes;
1027 for (var i = 0; i < children.length; i++) {
1028 var child = children[i];
1029 if (child.nodeType == Node.ELEMENT_NODE) {
1030 hasChildElems = true;
1031 var nodeName = child.nodeName;
1032 if (!(nodeName in parsed))
1033 parsed[nodeName] = [];
1034 parsed[nodeName].push(Element_parseChildNodes(child));
1039 var attrs = node.attributes;
1040 for (var i = 0; i < attrs.length; i++) {
1041 var attrName = '@' + attrs[i].nodeName;
1042 var attrValue = attrs[i].nodeValue;
1043 parsed[attrName] = attrValue;
1046 // if no nested elements, get text content
1047 if (node.hasChildNodes() && !hasChildElems) {
1048 if (node.attributes.length)
1049 parsed['#text'] = node.firstChild.nodeValue;
1051 parsed = node.firstChild.nodeValue;
1057 /* do not remove trailing bracket */