PDA

View Full Version : xml namespaces



sekaijin
8 Mar 2008, 7:25 AM
Hi

Before Extjs I'm using jQuery and I've partialy added xml name space support
How Extjs support xmlNS ??

I've there usages

$('prfx:tag') //for get prefixed tags
$(':NS(my.urn, tag)') //for get tags defined on my.urn name space.

the first call return only prfx:tag tags
the second return a pr

sekaijin
9 Mar 2008, 7:45 AM
Hi

i've looking Ext.DomQuery.js and does not support dom2 namespaces

I've change somme lines
adding \! to support tag selector prfx!tag

79 var modeRe = /^(\s?[\/>+~\!]\s?|\s|$)/;
80 var tagTokenRe = /^(#)?([\w\!-\*]+)/;
convert ! to : for tagName selector

152 tagName = tagName.replace('!',':');
add : support on attribute

576 re: /^(?:([\[\{])(?:@)?(([\w-]+:)?([\w-]+))\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
577 select: 'n = byAttribute(n, "{2}", "{6}", "{5}", "{1}");'

now you can select node like

var E1 = Ext.select('[@id=dock2]');
var E2 = Ext.select('[@fast:class=Switcher]');
var E3 = Ext.select('body');
var E4 = Ext.select('fast!block');
var E5 = Ext.select('fast!block[@fast:class=Switcher]');
I don't ave added urn redirect namespace support.


By
A+JYT

sekaijin
10 Mar 2008, 2:59 AM
Hi

i've added namspace support

I've change somme lines
change tagTokenRe (the previus change of nodeRe is not necessairy line 79)

79 var modeRe = /^(\s?[\/>+~]\s?|\s|$)/;
80 var tagTokenRe = /^(#)?((((\([\w-\*:\.]+\))|([\w-\*]+))!)?([\w-\*]+))/;
add namespace table initialiation


82 if ('undefined' == typeof(document.namespaces)) {//init global namespaces array if undefined
83 document.namespaces = new Array();
83 attibutes=document.documentElement.attributes;
84 i = 0;
85 for (x = 0; x < attibutes.length; x++) {
86 attr = attibutes[x];
87 if (/xmlns:/.test(attr.nodeName)) {
88 var matches = attr.nodeName.split(/:/);
89 var namespace = {
90 name: matches[1],
91 urn: attr.value};
92 document.namespaces[i++] = namespace;
93 }
94 }
95 }

convert ! to : for tagName selector and add namespace search

168 tagName = tagName.replace('!',':');
169 var am = tagName.match (/(\((.*)\)):(.*)/);
170 if (am){
171 var namespace = Ext.DomQuery.getNS(am[2]);
172 if (namespace) {
173 tagName = namespace.name+':'+ am[3];
174 }
175 }
add : support on attribute

616 re: /^(?:([\[\{])(?:@)?((((\([\w-\/\:\.]+\))|([\w-]+)):)?([\w-]+))\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
617 select: 'n = byAttribute(n, "{2}", "{9}", "{8}", "{1}");'
and on buAttribute finction

268 var am = attr.match (/(\((.*)\)):(.*)/);
269 if (am){
270 var namespace = Ext.DomQuery.getNS(am[2]);
271 if (namespace) {
272 attr = namespace.name+':'+ am[3];
273 }
274 }

now you can select node like


<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fast="urn:org.jquery.fast">
....
<div fast:class="Switcher">....
</html>


var E1 = Ext.select('[@id=dock2]');
var E2 = Ext.select('[@fast:class=Switcher]');
var E3 = Ext.select('body');
var E4 = Ext.select('fast!block');
var E5 = Ext.select('fast!block[@fast:class=Switcher]');
var E6 = Ext.select('[@(urn:org.jquery.fast):class=Switcher]');
var E7 = Ext.select('(urn:org.jquery.fast)!block');
var E8 = Ext.select('(urn:org.jquery.fast)!block[@(urn:org.jquery.fast):class=Switcher]');



By
A+JYT

sekaijin
10 Mar 2008, 6:26 AM
Hi
for tag in namespace i've choose ! selector like

var E4 = Ext.select('fast!block');

but this choise introduce an error (all html comment are acceted as tag)

I've change it to @ selector

80 var tagTokenRe = /^(#)?((((\([\w-\*:\.]+\))|([\w-\*]+))@)?([\w-\*]+))/;

so in the byAttribute function for compatibilty with IE change the lines

288 var sp = attr.match (/(.*):(.*)/);
289 if (sp) {
290 a= Ext.get(ci).getAttributeNS(sp[1],sp[2])
291 } else {
292 a = ci.getAttribute(attr);
293 }

By

sekaijin
12 Mar 2008, 11:12 AM
Hi
Ext implement getAttributeNS(ns, attr) to get an namespace attribut. but this method return an attribute was not in name space.

the xmlnamespaces are defined for define many attributes or tags was have same name for different use.
[code]<input type="text" xmlns:check="urn:org.verify" check:type="date" />[code]
the attribute type is defined on html global namspace and on org.verify first for displayong and text box second for verify the value.

the DOM2 sp