12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991 |
- /*
- XPath.js, an JavaScript implementation of XML Path Language (XPath) Version 1.0
- Copyright (C) 2008 Henrik Lindqvist <henrik.lindqvist@llamalab.com>
-
- This library is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- (function (w, d, f) {
- if (document.implementation.hasFeature("XPath", "3.0")
- && !document.createNSResolver)
- {
- function XPath(e) {
- this.e = e;
- this.i = 0;
- this.js = [ 'with(XPath){return ', '}' ];
- this.expression(1, 1) || this.error();
- return new Function('n', 'nsr', this.js.join(''));
- }
- XPath.ie = /MSIE/.test(navigator.userAgent);
- XPath.prototype = {
- match : function(rx, x) {
- var m, r;
- if (!(m = rx.exec(this.e.substr(this.i)))
- || (typeof x == 'number' && !(r = m[x]))
- || (typeof x == 'object' && !(r = x[m[1]])))
- {
- return false;
- }
- this.m = m;
- this.i += m[0].length;
- return r || m;
- },
- error : function(m) {
- m = (m || 'Syntax error') + ' at index ' + this.i + ': ' + this.e.substr(this.i);
- var e;
- try {
- e = new XPathException(51, m);
- } catch (x) {
- e = new Error(m);
- }
- throw e;
- },
- step : function(l, r, s, n) {
- var i = 3;
- if (this.match(/^(\/\/?|\.\.?|@)\s*/, 1)) {
- switch (this.m[1]) {
- case '/':
- if (s)
- {
- this.error();
- }
- if (!n)
- {
- return this.step(l, r, 1);
- }
- this.js.splice(l, 0, ' axis(axes["', 'document-root', '"],');
- i += this.nodeTypes.node.call(this, l + i);
- s = 1;
- break;
- case '//':
- if (s)
- {
- this.error();
- }
- this.js.splice(l, 0, ' axis(axes["', 'descendant-or-self', '"],');
- i += this.nodeTypes.node.call(this, l + i);
- s = 1;
- break;
- case '.':
- if (!s && !n)
- {
- this.error();
- }
- this.js.splice(l, 0, ' axis(axes["', 'self', '"],');
- i += this.nodeTypes.node.call(this, l + i);
- s = 0;
- break;
- case '..':
- if (!s && !n)
- {
- this.error();
- }
- this.js.splice(l, 0, ' axis(axes["', 'parent', '"],');
- i += this.nodeTypes.node.call(this, l + i);
- s = 0;
- break;
- case '@':
- if (!s && !n)
- {
- this.error();
- }
- this.js.splice(l, 0, ' axis(axes["', 'attribute', '"],');
- i += this.nodeTest(l + i, 'node') || this.error('Missing nodeTest after @');
- s = 0;
- }
- }
- else if (!s && !n)
- {
- return s ? this.error() : 0;
- }
- else if (this.match(/^([ㄱ-ㅎ가-힣a-z]+(?:-[ㄱ-ㅎ가-힣a-z]+)*)\s*::\s*/, XPath.axes))
- {
- this.js.splice(l, 0, ' axis(axes["', this.m[1], '"],');
- i += this.nodeTest(l + i, (this.m[1] == 'attribute') ? 'node' : 'element') || this.error('Missing nodeTest after ::');
- s = 0;
- }
- else if (i = this.nodeTest(l, 'element'))
- {
- this.js.splice(l, 0, ' axis(axes["', 'child', '"],');
- i += 3;
- s = 0;
- }
- else
- {
- return 0;
- }
- for ( var j; j = this.predicate(l + i); i += j)
- {
- ;
- }
- if (n)
- {
- this.js.splice(r + i++, 0, n);
- }
- i += this.step(l, r + i, s);
- this.js.splice(r + i++, 0, ')');
- return i;
- },
- expression : function(l, r, p)
- {
- var o, i = this.operand(l);
- while (o = this.match(/^(or|and|!?=|[<>]=?|[|*+-]|div|mod)\s*/, this.operators))
- {
- if (p && p[0] >= o[0])
- {
- this.i -= this.m[0].length;
- break;
- }
- this.js.splice(l, 0, o[1]);
- i++;
- this.js.splice(l + i++, 0, o[2]);
- i += this.expression(l + i, r, o) || this.error('Missing operand');
- this.js.splice(l + i++, 0, o[3]);
- }
- return i;
- },
- operand : function(l)
- {
- if (this.match(/^(-?(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)|"[^"]*"|'[^']*')\s*/, 1))
- {
- this.js.splice(l, 0, this.m[1]);
- return 1;
- }
- var fn;
- if (fn = this.match(/^([ㄱ-ㅎ가-힣a-z]+(?:-[ㄱ-ㅎ가-힣a-z]+)*)\s*\(\s*/, this.functions))
- {
- var i = 1, j;
- this.js.splice(l, 0, fn[1]);
- do {
- if (j)
- {
- this.js.splice(l + i++, 0, ',');
- }
- i += (j = this.expression(l + i, l + i));
- } while (j && this.match(/^,\s*/));
- this.match(/^\)\s*/) || this.error('Missing (');
- if (fn[0])
- {
- if (j)
- {
- this.js.splice(l + i++, 0, ',');
- }
- this.js.splice(l + i++, 0, fn[0]);
- }
- if (fn[2])
- {
- this.js.splice(l + i++, 0, fn[2]);
- }
- else if (j > 1)
- {
- this.error('Function has arguments');
- }
- i += this.step(l, l + i);
- return i;
- }
- if (this.match(/^\(\s*/))
- {
- var i = 1;
- this.js.splice(l, 0, '(');
- i += this.expression(l + i, l + i);
- this.match(/^\)\s*/) || this.error('Missing )');
- this.js.splice(l + i++, ')');
- return i;
- }
- return this.step(l, l, 0, '[n]');
- },
- operators : {
- '|' : [ 1, 'union(', ',', ')' ],
- 'or' : [ 1, 'bool(', ')||bool(', ')' ],
- 'and' : [ 2, 'bool(', ')&&bool(', ')' ],
- '=' : [ 3, 'compare(eq,', ',', ')' ],
- '!=' : [ 3, 'compare(ne,', ',', ')' ],
- '<' : [ 4, 'compare(lt,', ',', ')' ],
- '>' : [ 4, 'compare(gt,', ',', ')' ],
- '<=' : [ 4, 'compare(le,', ',', ')' ],
- '>=' : [ 4, 'compare(ge,', ',', ')' ],
- '+' : [ 5, 'number(', ')+number(', ')' ],
- '-' : [ 5, 'number(', ')-number(', ')' ],
- '*' : [ 6, 'number(', ')*number(', ')' ],
- 'div' : [ 6, 'number(', ')/number(', ')' ],
- 'mod' : [ 6, 'number(', ')%number(', ')' ]
- },
- functions : {
- // Node Set
- 'last' : [ 0, 'nl.length' ],
- 'position' : [ 0, '(i+1)' ],
- 'count' : [ 'nl', '(', '.length||0)' ],
- 'id' : [ 'n', 'id(', ')' ],
- 'local-name' : [ 'nl', 'localName(', ')' ],
- 'namespace-uri' : [ 'nl', 'namespaceURI(', ')' ],
- 'name' : [ 'nl', 'qName(', ')' ],
- // String
- 'string' : [ 'n', 'string(', ')' ],
- 'concat' : [ 0, 'concat(', ')' ],
- 'starts-with' : [ 0, 'startsWith(', ')' ],
- 'contains' : [ 0, 'contains(', ')' ],
- 'substring-before' : [ 0, 'substringBefore(', ')' ],
- 'substring-after' : [ 0, 'substringAfter(', ')' ],
- 'substring' : [ 0, 'substring(', ')' ],
- 'string-length' : [ 'n', 'string(', ').length' ],
- 'normalize-space' : [ 'n', 'normalizeSpace(', ')' ],
- 'translate' : [ 0, 'translate(', ')' ],
- // Boolean
- 'boolean' : [ 0, 'bool(', ')' ],
- 'not' : [ 0, '!bool(', ')' ],
- 'true' : [ 0, 'true ' ],
- 'false' : [ 0, 'false ' ],
- // 'lang' : [],
- // Number
- 'number' : [ 'n', 'number(', ')' ],
- 'floor' : [ 0, 'Math.floor(number(', '))' ],
- 'ceiling' : [ 0, 'Math.ceil(number(', '))' ],
- 'round' : [ 0, 'Math.round(number(', '))' ],
- 'sum' : [ 0, 'sum(', ')' ]
- },
- predicate : function(l)
- {
- var i = 0;
- if (this.match(/^\[\s*/))
- {
- if (i = this.expression(l, l))
- {
- this.js.splice(l, 0, 'function(n,i,nl){with(XPath){var r=');
- i++;
- this.js.splice(l + i++, 0, ';return typeof r=="number"?Math.round(r)==i+1:bool(r)}},');
- }
- this.match(/^\]\s*/) || this.error('Missing ]');
- }
- return i;
- },
- nodeTest : function(l, t)
- {
- var fn;
- if (fn = this.match(/^([ㄱ-ㅎ가-힣a-z]+(?:-[ㄱ-ㅎ가-힣a-z]+)*)\(([^)]*)\)\s*/, this.nodeTypes))
- {
- return fn.call(this, l, this.m[2]);
- }
- if (this.match(/^\*\s*/))
- {
- return this.nodeTypes[t].call(this, l);
- }
- return this.nodeName(l);
- },
- nodeType : function(l, t)
- {
- this.js.splice(l, 0, 'function(n){return n.nodeType==', t, '},');
- return 3;
- },
- nodeTypes :
- {
- 'node' : function(l)
- {
- this.js.splice(l, 0, 'null,');
- return 1;
- },
- 'element' : function(l)
- {
- return this.nodeType(l, 1);
- },
- 'attribute' : function(l)
- {
- return this.nodeType(l, 2);
- },
- 'text' : function(l)
- {
- return this.nodeType(l, 3);
- },
- 'processing-instruction' : function(l, t)
- {
- if (!t)
- {
- return this.nodeType(l, 7);
- }
- this.js.splice(l, 0, 'function(n){return n.nodeType==7&&n.target==', t, '},');
- return 3;
- },
- 'comment' : function(l)
- {
- return this.nodeType(l, 8);
- }
- },
- nodeName : function(l)
- {
- if (!this.match(/^([ㄱ-ㅎ가-힣a-zA-Z0-9_]+(?:-?[ㄱ-ㅎ가-힣a-zA-Z0-9]+)*)(?::([ㄱ-ㅎ가-힣a-zA-Z0-9_]+(?:-?[ㄱ-ㅎ가-힣a-zA-Z0-9]+)*))?\s*/, 1))
- {
- return 0;
- }
- if (this.m[2])
- {
- this.js.splice(l, 0, 'function(n){if(!nsr)throw new XPathException(14);return "',
- this.m[2], '"==', XPath.ie ? 'n.baseName' : 'n.localName',
- '&&nsr.lookupNamespaceURI("', this.m[1],
- '")==n.namespaceURI},');
- return 7;
- }
- else
- {
- this.js.splice(l, 0, 'function(n){return/^', this.m[1], '$/i.test(n.nodeName)},');
- return 3;
- }
- }
- };
- XPath.order = function(l, r)
- {
- var x = l.compareDocumentPosition ? l.compareDocumentPosition(r) : XPath.compareDocumentPosition.call(l, r);
- if (x & 32)
- {
- l = Array.prototype.indexOf.call(l.attributes, l);
- r = Array.prototype.indexOf.call(r.attributes, r);
- return (l < r) ? -1 : (l > r) ? 1 : 0;
- }
- if (!x)
- {
- if (l == r)
- {
- return 0;
- }
- if ((l = l.ownerElement) && (r = r.ownerElement))
- {
- return XPath.order(l, r);
- }
- return XPath.ie ? 1 : 0;
- }
- return 3 - ((x & 6) || 3);
- };
- // Runtime - Operand
- XPath.compare = function(fn, l, r)
- {
- if (l instanceof Array && r instanceof Array)
- {
- var ls = l.map(this.string), rs = r.map(this.string);
- for (l = ls.length; --l >= 0;)
- {
- for (r = rs.length; --r >= 0;)
- {
- if (!fn(ls[l], rs[r]))
- {
- return false;
- }
- }
- }
- return true;
- }
- if (l instanceof Array)
- {
- for ( var i = l.length; --i >= 0;)
- {
- if (!fn(this[typeof r](l[i]), r))
- {
- return false;
- }
- }
- return l.length > 0;
- }
- if (r instanceof Array)
- {
- for ( var i = r.length; --i >= 0;)
- {
- if (!fn(l, this[typeof l](r[i])))
- {
- return false;
- }
- }
- return r.length > 0;
- }
- if (typeof l == 'boolean' || typeof r == 'boolean')
- {
- return fn(this.bool(l), this.bool(r));
- }
- if (typeof l == 'number' || typeof r == 'number')
- {
- return fn(this.number(l), this.number(r));
- }
- return fn(this.string(l), this.string(r));
- };
- XPath.eq = function(l, r)
- {
- return l == r;
- };
- XPath.ne = function(l, r)
- {
- return l != r;
- };
- XPath.lt = function(l, r)
- {
- return l < r;
- };
- XPath.gt = function(l, r)
- {
- return l > r;
- };
- XPath.le = function(l, r)
- {
- return l <= r;
- };
- XPath.ge = function(l, r)
- {
- return l >= r;
- };
- // Runtime - Node Set
- XPath.id = function(s, n)
- {
- if (arguments.length == 1)
- {
- n = s;
- }
- var nl = [];
- for ( var id = this.string(s).split(/\s+/), i = id.length; --i >= 0;)
- {
- if (s = (n.ownerDocument || n).getElementById(id[i]))
- {
- nl.push(s);
- }
- }
- return nl.sort(this.order);
- };
- XPath.localName = new Function('nl', 'return (nl.length&&nl[0].' + (XPath.ie ? 'baseName' : 'localName') + ')||""');
- XPath.namespaceURI = function(nl)
- {
- return (nl.length && nl[0].namespaceURI) || '';
- };
- XPath.qName = function(nl)
- {
- return (nl.length && nl[0].nodeName) || '';
- };
- XPath.union = function(a, b)
- {
- if (!a.length)
- {
- return b;
- }
- if (!b.length)
- {
- return a;
- }
- var nl = [], i = a.length - 1, j = b.length - 1;
- for (;;)
- {
- switch (this.order(a[i], b[j]))
- {
- case -1:
- nl.unshift(b[j--]);
- break;
- case 0:
- j--;
- case 1:
- nl.unshift(a[i--]);
- break;
- default:
- throw new Error('Invalid order');
- }
- if (i < 0)
- {
- if (++j > 0)
- {
- nl.unshift.apply(nl, nl.slice.call(b, 0, j));
- }
- break;
- }
- if (j < 0)
- {
- if (++i > 0)
- {
- nl.unshift.apply(nl, nl.slice.call(a, 0, i));
- }
- break;
- }
- }
- return nl;
- };
- // Runtime - String
- XPath.string = XPath.object = function(v)
- {
- if (v instanceof Array && typeof (v = v[0]) == 'undefined')
- {
- return '';
- }
- if (typeof v == 'string')
- {
- return v;
- }
- switch (v.nodeType)
- {
- case 1:
- case 9:
- case 11:
- return Array.prototype.map.call(v.childNodes, this.string, this).join('');
- default:
- return v.nodeValue || '';
- }
- return String(v);
- };
- XPath.concat = function()
- {
- return Array.prototype.map.call(arguments, this.string, this).join('');
- };
- XPath.startsWith = function(a, b)
- {
- return this.string(a).substr(0, (b = this.string(b)).length) == b;
- };
- XPath.contains = function(a, b)
- {
- return this.string(a).indexOf(this.string(b)) != -1;
- };
- XPath.substringBefore = function(a, b)
- {
- a = this.string(a);
- b = a.indexOf(this.string(b));
- return b != -1 ? a.substr(0, b) : '';
- };
- XPath.substringAfter = function(a, b)
- {
- a = this.string(a);
- b = this.string(b);
- var i = a.indexOf(b);
- return i != -1 ? a.substr(i + b.length) : '';
- };
- XPath.substring = function(s, i, l)
- {
- s = this.string(s);
- i = Math.round(this.number(i)) - 1;
- return (arguments.length == 2) ? s.substr(i < 0 ? 0 : i) : s.substr(i < 0 ? 0 : i, Math.round(this.number(l)) - Math.max(0, -i));
- };
- XPath.normalizeSpace = function(s)
- {
- return this.string(s).replace(/^\s+/, '').replace(/\s+$/, '').replace(/\s+/g, ' ');
- };
- XPath.translate = function(a, b, c)
- {
- a = this.string(a);
- b = this.string(b);
- c = this.string(c);
- var o = [], l = a.length, i = 0, j, x;
- while (--l >= 0)
- {
- if ((j = b.indexOf(x = a.charAt(i++))) == -1 || (x = c.charAt(j)))
- {
- o.push(x);
- }
- }
- return o.join('');
- };
- // Runtime - Boolean
- XPath.bool = XPath['boolean'] = function(v)
- {
- if (typeof v == 'boolean')
- {
- return v;
- }
- if (v instanceof Array || typeof v == 'string')
- {
- return v.length > 0;
- }
- return Boolean(v);
- };
- // Runtime - Number
- XPath.number = function(v)
- {
- if (v instanceof Array && typeof (v = v[0]) == 'undefined')
- {
- return 0;
- }
- if (typeof v == 'number')
- {
- return v;
- }
- if (typeof v == 'boolean')
- {
- return v ? 1 : 0;
- }
- return Number(this.string(v));
- };
- XPath.sum = function(nl)
- {
- var r = 0, i = nl.length;
- while (--i >= 0)
- {
- r += this.number(nl[i]);
- }
- return r;
- };
- // Runtime - Axis
- XPath.walk = function(n, nl)
- {
- var x, c = n.firstChild;
- while (c)
- {
- nl.push(c);
- if (x = c.firstChild)
- {
- c = x;
- }
- else
- {
- for (x = c; !(c = x.nextSibling) && (x = x.parentNode) && (x != n);)
- {
- ;
- }
- }
- }
- return nl;
- };
- XPath.axes = {
- 'ancestor' : function(n)
- {
- var nl = [];
- while (n = n.parentNode)
- {
- nl.unshift(n);
- }
- return nl;
- },
- 'ancestor-or-self' : function(n)
- {
- var nl = [];
- do
- {
- nl.unshift(n)
- }
- while (n = n.parentNode);
- return nl;
- },
- 'attribute' : new Function
- (
- 'n',
- 'var nl = [], a = n.attributes;if(a){attr:for(var x,i=a.length;--i>=0;){if(!(x=a[i]).specified){' + (XPath.ie ? 'switch(x.nodeName){case"selected":case"value":if(x.nodeValue)break;default:continue attr;}'
- : 'continue;') + '}nl.unshift(x);}}return nl;'),
- 'child' : function(n)
- {
- return n.childNodes || [];
- },
- 'descendant' : function(n)
- {
- return this.walk(n, []);
- },
- 'descendant-or-self' : function(n)
- {
- return this.walk(n, [ n ]);
- },
- 'following' : function(n)
- {
- var nl = [], x;
- while (n)
- {
- if (x = n.nextSibling)
- {
- nl.push(n = x);
- if (x = n.firstChild)
- {
- nl.push(n = x);
- }
- }
- else
- {
- n = n.parentNode;
- }
- }
- return nl;
- },
- 'following-sibling' : function(n)
- {
- var nl = [];
- while (n = n.nextSibling)
- {
- nl.push(n);
- }
- return nl;
- },
- 'parent' : function(n)
- {
- return n.parentNode ? [ n.parentNode ] : [];
- },
- 'preceding' : function(n)
- {
- var nl = [], x, p = n.parentNode;
- while (n)
- {
- if (x = n.previousSibling)
- {
- for (n = x; x = n.lastChild; n = x)
- {
- ;
- }
- nl.unshift(n);
- }
- else if (n = n.parentNode)
- {
- if (n == p)
- {
- p = p.parentNode;
- }
- else
- {
- nl.unshift(n);
- }
- }
- }
- return nl;
- },
- 'preceding-sibling' : function(n)
- {
- var nl = [];
- while (n = n.previousSibling)
- {
- nl.unshift(n);
- }
- return nl;
- },
- 'self' : function(n)
- {
- return [ n ];
- },
- 'document-root' : function(n)
- {
- return [ n.ownerDocument || n ];
- }
- };
- XPath.axis = function(fn, nt/* , pr..., nl */)
- {
- var r, x, al = arguments.length - 1, nl = arguments[al], ap = Array.prototype;
- for ( var i = 0, j, l = nl.length; --l >= 0;)
- {
- x = fn.call(this, nl[i++]);
- if (nt && x.length)
- {
- x = ap.filter.call(x, nt, this);
- }
- for (j = 2; j < al && x.length; x = ap.filter.call(x, arguments[j++], this))
- {
- ;
- }
- r = r ? this.union(r, x) : x;
- }
- return r || [];
- };
- XPath.cache = {};
- /**
- * Extends the native <code>Node</code> class with additional
- * functionality.
- * <p>
- * Not available in Internet Exporer which don’t have a
- * <code>Node</code> class.
- * </p>
- * <p>
- * See <a
- * href="http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/core.html#ID-1950641247"
- * target="_blank">http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/core.html#ID-1950641247</a></code>.
- * </p>
- *
- * @class Node
- * @author Henrik Lindqvist <<a
- * href="mailto:henrik.lindqvist@llamalab.com">henrik.lindqvist@llamalab.com</a>>
- */
- /**
- * Compares a node with this node with regard to their position in the
- * document and according to the document order.
- * <p>
- * When comparing two attribute nodes; <code>32</code> is returned if they
- * have the same <code>ownerElement</code>, otherwise <code>0</code>.
- * This is probably not standard, but it’s what Firefox return, so we
- * do the same.
- * </p>
- *
- * <pre>
- * DOCUMENT_POSITION_DISCONNECTED = 1;
- * DOCUMENT_POSITION_PRECEDING = 2;
- * DOCUMENT_POSITION_FOLLOWING = 4;
- * DOCUMENT_POSITION_CONTAINS = 8;
- * DOCUMENT_POSITION_IS_CONTAINED = 16;
- * DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 32;
- * </pre>
- *
- * <p>
- * See <a
- * href="http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/core.html#Node3-compareDocumentPosition"
- * target="_blank">http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/core.html#Node3-compareDocumentPosition</a></code>.
- * </p>
- *
- * @function {number} compareDocumentPosition
- * @param {Node}
- * n - node to compare against.
- * @returns <code>0</code> for nodes are equals or a number with some of
- * the above bits set.
- */
- /**
- * Check if this node contains another node.
- *
- * @function {boolean} contains
- * @param {Node}
- * n - node to compare against.
- * @returns <code>true</code> if <code>this</code> node cotains node
- * <code>n</code>.
- */
- function compareDocumentPosition(n)
- {
- if (this == n)
- {
- return 0; // Same
- }
- if (this.nodeType == 2 && n.nodeType == 2)
- {
- return (this.ownerElement && this.ownerElement == n.ownerElement) ? 32 : 0; // IMPLEMENT_SPECIFIC
- }
- var l = this.ownerElement || this, r = n.ownerElement || n;
- if (l.sourceIndex >= 0 && r.sourceIndex >= 0 && l.contains && r.contains)
- {
- return (((l.contains(r) && 16) || (r.contains(l) && 8)) | ((l.sourceIndex < r.sourceIndex && 4) || (r.sourceIndex < l.sourceIndex && 2))) || 1;
- }
- var la = l, ra = r, ld = 0, rd = 0;
- while (la = la.parentNode)
- {
- ld++;
- }
- while (ra = ra.parentNode)
- {
- rd++;
- }
- if (ld > rd)
- {
- while (ld-- != rd)
- {
- l = l.parentNode;
- }
- if (l == r)
- {
- return 2 | 8; // Preceding|Contains
- }
- }
- else if (rd > ld)
- {
- while (rd-- != ld)
- {
- r = r.parentNode;
- }
- if (r == l)
- {
- return 4 | 16; // Following|Contained By
- }
- }
- while ((la = l.parentNode) != (ra = r.parentNode))
- {
- if (!(l = la) || !(r = ra))
- {
- return 1; // Disconnected
- }
- }
- while (l = l.nextSibling)
- {
- if (l == r)
- {
- return 4; // Following
- }
- }
- return 2; // Preceding
- };
-
- if (w.Node)
- {
- var np = w.Node.prototype;
- if (f || !np.compareDocumentPosition)
- {
- np.compareDocumentPosition = compareDocumentPosition;
- }
- if (f || !np.contains)
- {
- np.contains = function(n)
- {
- return Boolean(this.compareDocumentPosition(n) & 16);
- };
- }
- }
- else
- {
- XPath.compareDocumentPosition = compareDocumentPosition;
- }
-
- /**
- * Exception throw when parser or expression fails.
- * <p>
- * See
- * <code><a href="http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathException" target="_blank">http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathException</a></code>.
- * </p>
- *
- * @class XPathException
- * @author Henrik Lindqvist <<a
- * href="mailto:henrik.lindqvist@llamalab.com">henrik.lindqvist@llamalab.com</a>>
- */
- /**
- * Namespace error.
- *
- * @property {static read number} NAMESPACE_ERR
- */
- /**
- * Expression syntax error.
- *
- * @property {static read number} INVALID_EXPRESSION_ERR
- */
- /**
- * Result type error.
- *
- * @property {static read number} TYPE_ERR
- */
- /**
- * XPathException constructor.
- *
- * @constructor XPathException
- * @param {number}
- * c - error code.
- * @param {string}
- * m - error message.
- * @see NAMESPACE_ERR
- * @see INVALID_EXPRESSION_ERR
- * @see TYPE_ERR
- */
- /**
- * Exception name.
- *
- * @property {read string} name
- */
- /**
- * Exception code.
- *
- * @property {read number} code
- * @see NAMESPACE_ERR
- * @see INVALID_EXPRESSION_ERR
- * @see TYPE_ERR
- */
- /**
- * Exception message.
- *
- * @property {read string} message
- */
- if (f || !w.XPathException)
- {
- function XPathException(c, m)
- {
- this.name = 'XPathException';
- this.code = c;
- this.message = m;
- };
- var e = XPathException, p = new Error;
- p.toString = function()
- {
- return this.name + ':' + this.message;
- };
- e.prototype = p;
- e.NAMESPACE_ERR = 14;
- e.INVALID_EXPRESSION_ERR = 51;
- e.TYPE_ERR = 52;
- w.XPathException = e;
- }
-
- /**
- * Namespace resolver.
- * <p>
- * See
- * <code><a href="http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathNSResolver" target="_blank">http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathNSResolver</a></code>.
- * </p>
- *
- * @class XPathNSResolver
- * @see XPathEvaluator.createNSResolver
- * @author Henrik Lindqvist <<a
- * href="mailto:henrik.lindqvist@llamalab.com">henrik.lindqvist@llamalab.com</a>>
- */
- /**
- * Look up a namespace URI by it’s prefix use in document.
- *
- * @function {string} lookupNamespaceURI
- * @param {string}
- * p - <code>xmlns:</code> prefix, empty string for
- * <code>targetNamespace</code>.
- * @returns associated namespace URI, or <code>undefined</code> if none is
- * found.
- */
- if (f || !w.XPathNSResolver)
- {
- function XPathNSResolver(n)
- {
- this.ns = {};
- for ( var m, a, i = n.attributes.length; --i >= 0;)
- {
- if (m = /xmlns:(.+)/.exec((a = n.attributes[i]).nodeName))
- {
- this.ns[m[1]] = a.nodeValue;
- }
- }
- this.ns[''] = n.getAttribute('targetNamespace');
- }
- XPathNSResolver.prototype = {
- lookupNamespaceURI : function(p) {
- return this.ns[p || ''];
- }
- };
- w.XPathNSResolver = XPathNSResolver;
- }
- /**
- * A pre-parsed XPath expression.
- * <p>
- * See
- * <code><a href="http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathExpression" target="_blank">http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathExpression</a></code>.
- * </p>
- *
- * @class XPathExpression
- * @see XPathEvaluator.createExpression
- * @author Henrik Lindqvist <<a
- * href="mailto:henrik.lindqvist@llamalab.com">henrik.lindqvist@llamalab.com</a>>
- */
- /**
- * Evaluate this pre-parsed expression.
- *
- * @function {XPathResult} evaluate
- * @param {Node}
- * n - context node.
- * @param {number}
- * rt - return type, see <code>{@link XPathResult}</code>.
- * @param {XPathResult}
- * r - <code>{@link XPathResult}</code> that maybe reuse, or
- * <code>null</code>.
- * @returns a <code>{@link XPathResult}</code>.
- */
- if (f || !w.XPathExpression)
- {
- function XPathExpression(e, nsr)
- {
- this.fn = XPath.cache[e] || (XPath.cache[e] = new XPath(e));
- this.nsr = nsr;
- }
- XPathExpression.prototype =
- {
- evaluate : function(n, rt)
- {
- return new XPathResult(this.fn(n, this.nsr), rt);
- }
- };
- w.XPathExpression = XPathExpression;
- }
- /**
- * Container for XPath results.
- * <p>
- * See
- * <code><a href="http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult" target="_blank">http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult</a></code>.
- * </p>
- *
- * @class XPathResult
- * @see XPathEvaluator.evaluate
- * @see XPathExpression.evaluate
- * @author Henrik Lindqvist <<a
- * href="mailto:henrik.lindqvist@llamalab.com">henrik.lindqvist@llamalab.com</a>>
- */
- /**
- * Result will be accessed unconverted as the expression returned it.
- *
- * @property {static read number} ANY_TYPE
- */
- /**
- * Result will be accessed as a number.
- *
- * @property {static read number} NUMBER_TYPE
- * @see numberValue
- */
- /**
- * Result will be accessed as a string.
- *
- * @property {static read number} STRING_TYPE
- * @see stringValue
- */
- /**
- * Result will be accessed as boolean.
- *
- * @property {static read number} BOOLEAN_TYPE
- * @see booleanValue
- */
- /**
- * Result will be accessed iteratively, node order insignificant.
- * <p>
- * This is equal to <code>{@link ORDERED_NODE_ITERATOR_TYPE}</code> since
- * the result is always document-ordered.
- * </p>
- *
- * @property {static read number} UNORDERED_NODE_ITERATOR_TYPE
- * @see iterateNext
- */
- /**
- * Result will be accessed iteratively which must be document-ordered.
- *
- * @property {static read number} ORDERED_NODE_ITERATOR_TYPE
- * @see iterateNext
- */
- /**
- * Result will be accessed as a snapshot list of nodes, node order
- * insignificant.
- * <p>
- * This is equal to <code>{@link ORDERED_NODE_SNAPSHOT_TYPE}</code> since
- * the result is always document-ordered.
- * </p>
- *
- * @property {static read number} UNORDERED_NODE_SNAPSHOT_TYPE
- * @see snapshotLength
- * @see snapshotItem
- */
- /**
- * Result will be accessed as a snapshot list of nodes which must be
- * document-ordered.
- *
- * @property {static read number} ORDERED_NODE_SNAPSHOT_TYPE
- * @see snapshotLength
- * @see snapshotItem
- */
- /**
- * Result will be accessed as a single node value, any of the resulting
- * nodes.
- * <p>
- * This is equal to <code>{@link FIRST_ORDERED_NODE_TYPE}</code> since the
- * result is always document-ordered.
- * </p>
- *
- * @property {static read number} ANY_UNORDERED_NODE_TYPE
- * @see singleNodeValue
- */
- /**
- * Result will be accessed as a single node value, the first resulting node
- * in document-ordered.
- *
- * @property {static read number} FIRST_ORDERED_NODE_TYPE
- * @see singleNodeValue
- */
- /**
- * Convert result to number.
- *
- * @property {static read number} NUMBER_TYPE
- */
- /**
- * Convert result to number.
- *
- * @property {static read number} NUMBER_TYPE
- */
- /**
- * Convert result to number.
- *
- * @property {static read number} NUMBER_TYPE
- */
- /**
- * Convert result to number.
- *
- * @property {static read number} NUMBER_TYPE
- */
- /**
- * Convert result to number.
- *
- * @property {static read number} NUMBER_TYPE
- */
- /**
- * Resulting number.
- *
- * @property {read number} numberValue
- * @see NUMBER_TYPE
- */
- /**
- * Resulting string.
- *
- * @property {read string} stringValue
- * @see STRING_TYPE
- */
- /**
- * Resulting boolean.
- *
- * @property {read boolean} booleanValue
- * @see BOOLEAN_TYPE
- */
- /**
- * Signifies that the iterator has become invalid.
- *
- * @property {read boolean} invalidIteratorState
- * @see UNORDERED_NODE_ITERATOR_TYPE
- * @see ORDERED_NODE_ITERATOR_TYPE
- */
- /**
- * The number of nodes in the result snapshot.
- *
- * @property {read number} snapshotLength
- * @see UNORDERED_NODE_SNAPSHOT_TYPE
- * @see ORDERED_NODE_SNAPSHOT_TYPE
- */
- /**
- * The value of this single node result, maybe <code>undefined</code>.
- *
- * @property {read object} singleNodeValue
- * @see ANY_UNORDERED_NODE_TYPE
- * @see FIRST_ORDERED_NODE_TYPE
- */
- /**
- * Unconverted result as returned by our internal evaluator.
- * <p>
- * This is a non-standard property which is set to the raw unconverted
- * result from our expression evaluator. It’s of the type
- * <code>number</code>, <code>string</code>, <code>boolean</code> or
- * an <code>{@link Array}</code> with nodes depending on expression. If
- * you prefer to work with arrays instead of
- * <code>{@link XPathResult.snapshotItem}</code> You can check for this
- * property and use it directly.
- * </p>
- * <h3>Example</h3>
- *
- * <pre>
- * function selectNodes(expr) {
- * // Cross-browser safe way of selecting nodes and return an Array
- * var r = document.evaluate('//LI', document, null, 7, null);
- * if (typeof r.value != 'undefined')
- * return r.value;
- * var a = [];
- * for ( var i = r.snapshotLength; --i >= 0; a[i] = r.snapshotItem(i))
- * ;
- * return a;
- * }
- * </pre>
- *
- * @property {read object} value
- * @see ANY_TYPE
- */
- /**
- * Iterates and returns the next node from the resuling nodes.
- *
- * @function {object} iterateNext
- * @returns a <code>Node</code>, or <code>undefined</code> if there are
- * no more nodes.
- */
- /**
- * Returns the <code>index</code>th item in the snapshot collection.
- *
- * @function {object} snapshotItem
- * @param {number}
- * i - index of resuling node to return.
- * @returns the <code>Node</code>, at provided index or
- * <code>undefined</code> if invalid.
- */
- if (f || !w.XPathResult)
- {
- function XPathResult(r, rt)
- {
- if (rt == 0)
- {
- switch (typeof r)
- {
- default:
- rt++;
- case 'boolean':
- rt++;
- case 'string':
- rt++;
- case 'number':
- rt++;
- }
- }
- this.resultType = rt;
- switch (rt)
- {
- case 1:
- this.numberValue = XPath.number(r);
- return;
- case 2:
- this.stringValue = XPath.string(r);
- return;
- case 3:
- this.booleanValue = XPath.bool(r);
- return;
- case 4:
- case 5:
- if (r instanceof Array)
- {
- this.value = r;
- this.index = 0;
- this.invalidIteratorState = false;
- return;
- }
- break;
- case 6:
- case 7:
-
- if (r instanceof Array)
- {
- this.value = r;
- this.snapshotLength = r.length;
- return;
- }
- else if (r instanceof NodeList)
- {
- this.value = r;
- this.snapshotLength = r.length;
- return;
- }
- break;
- case 8:
- case 9:
- if (r instanceof Array)
- {
- this.singleNodeValue = r[0];
- return;
- }
- }
- throw new XPathException(52);
- }
- var r = XPathResult;
- r.ANY_TYPE = 0;
- r.NUMBER_TYPE = 1;
- r.STRING_TYPE = 2;
- r.BOOLEAN_TYPE = 3;
- r.UNORDERED_NODE_ITERATOR_TYPE = 4;
- r.ORDERED_NODE_ITERATOR_TYPE = 5;
- r.UNORDERED_NODE_SNAPSHOT_TYPE = 6;
- r.ORDERED_NODE_SNAPSHOT_TYPE = 7;
- r.ANY_UNORDERED_NODE_TYPE = 8;
- r.FIRST_ORDERED_NODE_TYPE = 9;
- r.prototype = {
- iterateNext : function()
- {
- switch (this.resultType)
- {
- case 4:
- case 5:
- return this.value[this.index++];
- }
- throw new XPathException(52);
- },
- snapshotItem : function(i)
- {
- switch (this.resultType)
- {
- case 6:
- case 7:
- return this.value[i];
- }
- throw new XPathException(52);
- }
- };
- w.XPathResult = r;
- }
- /**
- * An interface with the XPath functionality.
- * <p>
- * <code>Document.prototype</code> and/or <code>document</code> will be
- * extended using <code>{@link install}</code> to implements it’s
- * functions.
- * </p>
- * <p>
- * See
- * <code><a href="http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathEvaluator" target="_blank">http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathEvaluator</a></code>.
- * </p>
- *
- * @interface XPathEvaluator
- * @author Henrik Lindqvist <<a
- * href="mailto:henrik.lindqvist@llamalab.com">henrik.lindqvist@llamalab.com</a>>
- */
- /**
- * Non-standard function that extends the provided object with
- * <code>{@link XPathEvaluator}</code> functions.
- *
- * @function {static} install
- * @param {object}
- * o - object (i.e document node) to extend.
- * @param {optional
- * boolean} f - force replace the build-in function even if they
- * exists.
- */
- /**
- * Creates a pre-parsed expression.
- *
- * @function {XPathExpression} createExpression
- * @param {string}
- * e - expression.
- * @param {XPathNSResolver}
- * nsr - namespace resolver to use when evaluating, or
- * <code>null</code>.
- * @returns a new <code>{@link XPathExpression}</code>.
- */
- /**
- * Create a namespace resolver by scanning a node for <code>xmlns:</code>
- * attributes.
- *
- * @function {XPathNSResolver} createNSResolver
- * @param {Node}
- * n - an <code>Node</code> with defined namespace attributes
- * (i.e the documentElement).
- * @returns a new <code>{@link XPathNSResolver}</code>.
- */
- /**
- * Evaluate an expression.
- * <p>
- * Same as <code>new XPathExpression(e, nsr).evaluate(n, rt)</code>.
- * </p>
- *
- * @function {XPathResult} evaluate
- * @param {string}
- * e - XPath expression string.
- * @param {Node}
- * n - context node.
- * @param {XPathNSResolver}
- * nsr - namespace resolver to use when evaluating, or
- * <code>null</code>.
- * @param {number}
- * rt - return type, see <code>{@link XPathResult}</code>.
- * @param {XPathResult}
- * r - <code>{@link XPathResult}</code> that maybe reuse, or
- * <code>null</code>. Ignored.
- * @returns a <code>{@link XPathResult}</code>.
- */
- if (f || !w.XPathEvaluator)
- {
- function XPathEvaluator() {};
- var e = XPathEvaluator;
- e.prototype = {
- createExpression : function(e, nsr)
- {
- return new XPathExpression(e, nsr);
- },
- createNSResolver : function(n)
- {
- return new XPathNSResolver(n);
- },
- evaluate : function(e, n, nsr, rt)
- {
- return new XPathExpression(e, nsr).evaluate(n, rt);
- }
- };
- e.install = function(o, f)
- {
- for ( var k in XPathEvaluator.prototype)
- {
- if (f || !o[k])
- {
- o[k] = XPathEvaluator.prototype[k];
- }
- }
- };
- w.XPathEvaluator = e;
- if (w.Document)
- {
- e.install(w.Document.prototype, f);
- }
- else
- {
- e.install(document, f);
- }
- w.XPath = XPath;
- }
- }
- })(window, document, /WebKit/.test(navigator.userAgent));
- function XmlLib ()
- {
- };
- XmlLib.loadXMLFromString = function (strXml)
- {
- var docXML = null;
-
- // IE
- if(is_ie)
- {
- docXML = new ActiveXObject("Microsoft.XMLDOM");
- docXML.async = false;
- docXML.resolveExternals = true;
- docXML.validateOnParse = false;
- docXML.preserveWhiteSpace = true;
- docXML.loadXML(strXml);
- docXML.setProperty("SelectionLanguage", "XPath");
-
- }
- // Other
- else
- {
- var parser = new DOMParser();
- docXML = parser.parseFromString(strXml, "text/xml");
- }
- return docXML;
- };
- XmlLib.createXML = function (strRoot)
- {
- var docXML = null;
-
- // IE
- if(is_ie)
- {
- docXML = new ActiveXObject("Microsoft.XMLDOM");
- docXML.async = false;
- docXML.resolveExternals = true;
- docXML.validateOnParse = false;
- docXML.documentElement = docXML.createElement(strRoot);
- }
- // Other
- else
- {
- docXML = document.implementation.createDocument("", strRoot, null);
- }
-
- return docXML;
- };
- XmlLib.serializeToString = function (xnNode)
- {
- var strXml = null;
-
- // IE
- if (is_ie)
- {
- strXml = xnNode.xml;
- }
- // Other
- else
- {
- var serializer = new XMLSerializer();
- strXml = serializer.serializeToString(xnNode);
- }
-
- return strXml;
- };
- /**
- * Xml Node attribute 값을 얻어 온다.
- */
- XmlLib.getAttribute = function (xnNode, strAttName)
- {
- if (null != xnNode)
- {
- var nAttrSize = xnNode.attributes.length;
-
- for (var i = 0; i < nAttrSize; i++)
- {
- if (xnNode.attributes[i].nodeName == strAttName)
- {
- return xnNode.attributes[i].value;
- }
- }
- }
- return null;
- };
- /**
- * Xml Node attribute 를 설정한다
- *
- * Node.setAttribute(Node, "속성이름", "값")
- */
- XmlLib.setAttribute = function (xnNode, strAttName, strAttValue)
- {
- xnNode.setAttribute(strAttName, strAttValue);
- };
- XmlLib.createChild = function (xnParent, strNodeName)
- {
- var xnDoc = xnParent.ownerDocument;
- var xnChild = xnDoc.createElement(strNodeName);
- xnParent.appendChild(xnChild);
-
- return xnChild;
- };
- /**
- * 값을 가진 자식 노드를 생성한다.
- * @param nxParent (부모 노드)
- * @param strNodeName (생성할 자식노드 이름)
- * @param strValue (자식노드에 부여할 값)
- * @return xnNode (생성한 자식 노드)
- */
- XmlLib.createChildWithValue = function (xnParent, strNodeName, strValue)
- {
- if (null == strValue)
- {
- strValue = "";
- }
- var xnChild = XmlLib.createChild(xnParent, strNodeName);
- XmlLib.setTextValue(xnChild, strValue);
-
- return xnChild;
- };
- XmlLib.getTextValue = function (xnNode)
- {
- var strValue = "";
- try
- {
- if (Node.TEXT_NODE == xnNode.firstChild.nodeType || Node.CDATA_SECTION_NODE == xnNode.firstChild.nodeType)
- {
- strValue = xnNode.firstChild.nodeValue;
- }
- }
- catch (e)
- {
- }
- return strValue;
- };
- /**
- * @param xmlDoc 새로운 XML Node, impor된 Node가 child로 append 됩니다.
- * @param oldNode import 할 Node
- * @param bDeep 하위 노드 import 여부
- * @return 새롭게 import 된 Node
- */
- XmlLib.importChildNode = function (xnParent, xnChild, deep)
- {
- var xnNewChild = XmlLib.importNode(xnParent.ownerDocument, xnChild, deep);
- xnParent.appendChild(xnNewChild);
-
- return xnNewChild;
- };
- /**
- * @param xmlDoc 새로운 XML Document
- * @param xnNode import 할 Node
- * @param deep 하위 노드 import 여부
- * @return 새롭게 import 된 Node
- */
- XmlLib.importNode = function (docXML, xnNode, deep)
- {
- if (docXML.importNode)
- {
- return docXML.importNode(xnNode, deep);
- }
- else
- {
- return XmlLib.importNodeOld(docXML, xnNode, deep);
- }
- };
- XmlLib.importNodeOld = function (docXML, xnNode, bDeep)
- {
- bDeep = (bDeep == null) ? true : bDeep;
-
- var importChildNode = function(doc, srcNode, parent)
- {
- if (bDeep)
- {
- for (var i = 0; i < srcNode.childNodes.length; i++)
- {
- var node = XmlLib.importNode(doc, srcNode.childNodes.item(i), true);
- parent.appendChild(node);
- }
- }
- };
-
- var newNode = null;
- switch(xnNode.nodeType)
- {
- case Node.ATTRIBUTE_NODE:
- {
- if (null != docXML.createAttributeNS)
- {
- newNode = docXML.createAttributeNS(xnNode.namespaceURI, xnNode.nodeName);
- }
- else
- {
- newNode = docXML.createAttribute(xnNode.nodeName);
- }
- newNode.value = xnNode.value;
- break;
- }
- case Node.DOCUMENT_FRAGMENT_NODE:
- {
- newNode = docXML.createDocumentFragment();
- importChildNode(docXML, xnNode, newNode);
- break;
- }
- case Node.ELEMENT_NODE:
- {
- if (null != docXML.createElementNS)
- {
- newNode = docXML.createElementNS(xnNode.namespaceURI, xnNode.tagName);
- }
- else
- {
- newNode = docXML.createElement(xnNode.tagName);
- }
-
- for (var i = 0; i < xnNode.attributes.length; i++)
- {
- var attr = XmlLib.importNode(docXML, xnNode.attributes.item(i), bDeep);
- if (null != newNode.setAttributeNodeNS)
- {
- newNode.setAttributeNodeNS(attr);
- }
- else
- {
- newNode.setAttributeNode(attr);
- }
- }
- importChildNode(docXML, xnNode, newNode);
- break;
- }
- case Node.ENTITY_REFERENCE_NODE:
- {
- newNode = xnNode;
- break;
- }
- case Node.PROCESSING_INSTRUCTION_NODE:
- {
- newNode = docXML.createProcessingInstruction(xnNode.target, xnNode.data);
- break;
- }
- case Node.TEXT_NODE:
- case Node.CDATA_SECTION_NODE:
- case Node.COMMENT_NODE:
- {
- newNode = docXML.createTextNode(xnNode.nodeValue);
- break;
- }
- case Node.DOCUMENT_NODE:
- case Node.DOCUMENT_TYPE_NODE:
- case Node.NOTATION_NODE:
- case Node.ENTITY_NODE:
- throw "can not import " + xnNode.tagName;
- break;
- }
-
- return newNode;
- };
- XmlLib.setTextValue = function (xnNode, strValue)
- {
- if (xnNode.hasChildNodes() && (Node.TEXT_NODE == xnNode.firstChild.nodeType || Node.CDATA_SECTION_NODE == xnNode.firstChild.nodeType))
- {
- xnNode.firstChild.nodeValue = strValue;
- }
- else
- {
- var xmlText = xnNode.ownerDocument.createTextNode(strValue);
- xnNode.appendChild(xmlText);
- }
- };
- XmlLib.createCDATASection = function (xnNode, strValue)
- {
- var docXML = xnNode.ownerDocument;
-
- var xmlCDATA = docXML.createCDATASection(strValue);
-
- xnNode.appendChild(xmlCDATA);
- };
- XmlLib.transformToHTMLElement = function (heElement, xnNode, xnXSL)
- {
- try
- {
- // IE
- if (is_ie)
- {
- heElement.innerHTML = xnNode.transformNode(xnXSL);
- }
- // Other
- else
- {
- var objXslt = new XSLTProcessor();
- objXslt.importStylesheet(xnXSL);
-
- var resultFragment = objXslt.transformToFragment(xnNode, document);
- heElement.appendChild(resultFragment.firstChild);
-
- objXslt.reset();
- return;
- }
- }
- catch (e)
- {
- window.alert(e + " TrustFormSoonsu : transformToHTMLElement");
- }
- };
- XmlLib.selectSingleNode = function (xnNode, strPath)
- {
- if (null == xnNode || strPath.isEmpty())
- {
- return null;
- }
-
- var xmlSelectNode = null;
-
- xmlSelectNode = xnNode.selectSingleNode(strPath);
-
- return xmlSelectNode;
- };
- XmlLib.selectNodes = function (xnNode, strPath)
- {
- if (typeof(strPath) != "string")
- {
- return null;
- }
- if (null == xnNode || strPath.isEmpty())
- {
- return null;
- }
-
- var xlNode = null;
-
- xlNode = xnNode.selectNodes(strPath);
-
- return xlNode;
- };
- XmlLib.hasChildNodesExceptText = function (xnNode)
- {
- if (xnNode.hasChildNodes())
- {
- var xlChild = xnNode.childNodes;
- for (var i=0; i<xlChild.length; i++)
- {
- var xnChild = xlChild[i];
- if (Node.TEXT_NODE != xnChild.nodeType && Node.CDATA_SECTION_NODE != xnChild.nodeType)
- {
- return true;
- }
- }
- }
- return false;
- };
- /**
- * Document에서 Root ElementNode를 찾는다.
- */
- XmlLib.getRootElementNode = function (xnDoc)
- {
- var xnRoot;
- if (null != xnDoc)
- {
- if (Node.DOCUMENT_NODE == xnDoc.nodeType)
- {
- var xlChild = xnDoc.childNodes;
- for (var i=0; i<xlChild.length; i++)
- {
- var xnChild = xlChild[i];
- if (Node.PROCESSING_INSTRUCTION_NODE != xnChild.nodeType)
- {
- xnRoot = xnChild;
- break;
- }
- }
- }
- else
- {
- if (Node.PROCESSING_INSTRUCTION_NODE != xnChild.nodeType)
- {
- xnRoot = xnChild;
- }
- }
- }
- return xnRoot;
- };
- if (!window.Node)
- {
- var Node =
- {
- ELEMENT_NODE : 1,
- ATTRIBUTE_NODE : 2,
- TEXT_NODE : 3,
- CDATA_SECTION_NODE : 4,
- ENTITY_REFERENCE_NODE : 5,
- ENTITY_NODE : 6,
- PROCESSING_INSTRUCTION_NODE : 7,
- COMMENT_NODE : 8,
- DOCUMENT_NODE : 9,
- DOCUMENT_TYPE_NODE : 10,
- DOCUMENT_FRAGMENT_NODE : 11,
- NOTATION_NODE : 12
- };
- };
- /**
- * XML DOM에 Property 추가
- *
- * selectNodes()
- * selectSingleNode()
- */
- if (document.implementation.hasFeature("XPath", "3.0"))
- {
- // prototying the XMLDocument
- XMLDocument.prototype.selectNodes = function (strXPath, xnDoc)
- {
- try
- {
- if (!xnDoc)
- {
- xnDoc = this;
- }
-
- var xlNodeList = new DOMNodeList();
- if (this.createNSResolver)
- {
- var arItemList = this.evaluate(strXPath, xnDoc, this.createNSResolver(this.documentElement), XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
-
- for (var i = 0; i < arItemList.snapshotLength; i++)
- {
- xlNodeList.add(arItemList.snapshotItem(i));
- }
- }
- return xlNodeList;
- }
- catch (e)
- {
- window.alert(e + " TrustFormSoonsu : selectNodes");
- }
- };
-
- // prototying the Element
- Element.prototype.selectNodes = function (strXPath)
- {
- if (this.ownerDocument.selectNodes)
- {
- return this.ownerDocument.selectNodes(strXPath, this);
- }
- else
- {
- throw "Web Browser not Support Element.selectNodes()";
- }
- };
-
- // prototying the XMLDocument
- XMLDocument.prototype.selectSingleNode = function (strXPath, xnDoc)
- {
- if (!xnDoc)
- {
- xnDoc = this;
- }
- var xlNodeList = this.selectNodes(strXPath, xnDoc);
-
- if (xlNodeList.length > 0)
- {
- return xlNodeList.item(0);
- }
- else
- {
- return null;
- }
- };
-
- // prototying the Element
- Element.prototype.selectSingleNode = function (strXPath)
- {
- if (this.ownerDocument.selectSingleNode)
- {
- return this.ownerDocument.selectSingleNode(strXPath, this);
- }
- else
- {
- throw "Web Browser not Support Element.selectSingleNode()";
- }
- };
- };
|