source: other-projects/tipple-android/i-greenstone-server-files/greenstone/webapps/greenstone3/gs_ajax_utils.js@ 26917

Last change on this file since 26917 was 26899, checked in by davidb, 11 years ago

Tipple reborn after Chris's Summer of Code 2013

File size: 2.6 KB
Line 
1/*
2function loadAsync(sUri, SOAPMessage) {
3 var xmlHttp = XmlHttp.create();
4 xmlHttp.open("POST", sUri, true);
5 xmlHttp.onreadystatechange = function () {
6 if (xmlHttp.readyState == 4){
7 getTitle2(xmlHttp.responseXML, xmlHttp.responseText);
8 }
9 }
10 xmlHttp.setRequestHeader("SOAPAction", " ");
11 xmlHttp.setRequestHeader("Content-Type", "Content-Type: text/xml; charset=utf-8");
12
13 xmlHttp.send(SOAPMessage);
14}
15*/
16
17function messageToSOAP(message) {
18 return ['<?xml version="1.0" encoding="UTF-8"?>',
19 '<soapenv:Envelope ',
20 'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"',
21 'xmlns:xsd="http://www.w3.org/2001/XMLSchema"',
22 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">',
23 '<soapenv:Body>',
24 message,
25 '</soapenv:Body>',
26 '</soapenv:Envelope>'].join("");
27}
28
29function getText(element) { //get the text from possibly multiple text nodes
30 if (element.hasChildNodes()) {
31 var tempString = [];
32 for (var j = 0; j < element.childNodes.length; j++) {
33 if (element.childNodes[j].nodeType == Node.TEXT_NODE ) { // =2
34 tempString.push(element.childNodes[j].nodeValue);
35 }
36 else {
37 tempString.push('non text node: ');
38 }
39 }
40 return tempString.join("");
41 }
42 else {
43 return 'getText: element has no ChildNodes from which to extract Text';
44 }
45}
46
47function newOpenTag(name) {
48 return ['<', name, '>'].join("");
49}
50
51function newCloseTag(name) {
52 return ['</', name, '>'].join("");
53}
54
55function newEmptyTag(name) {
56 return ['<', name, '/>'].join("");
57}
58
59function newElement(name, content) {
60 return ['<', name, '>', content, '</', name, '>'].join("");
61}
62
63function newElementAtt1(name, content, attName, attValue) {
64 return ['<', name, ' ', attName, '="', attValue, '">', content, '</', name, '>'].join("");
65}
66
67function newElementAtt(name, content, nameArray, valueArray) {
68 var e = ['<', name, ' '];
69 for (i=0; i < nameArray.length; i++) {
70 e.push(newAttribute(nameArray[i], valueArray[i]));
71 }
72 e.push(['>', content, '</', name, '>']);
73 return e.join("");
74}
75
76function newAttribute(name, value) {
77 return [' ', name, '="', value, '"'].join("");
78}
79
80function countElementChildren(node) {
81 var count = 0;
82 var childList = node.childNodes;
83 for(var i=0; i < (childList.length); i++) {
84 var childNode = childList.item(i);
85 if ((childNode.nodeType == 1)) { // only count elements
86 count++;
87 }
88 }
89 return count;
90}
91
92function removeAllChildren(node) {
93 while (node.hasChildNodes()) {
94 node.removeChild(node.firstChild);
95 }
96}
97
98function isElement(node) {
99 if (node.nodeType == 1) {
100 return true; }
101 else {
102 return false;
103 }
104}
Note: See TracBrowser for help on using the repository browser.