1dp.sh.Brushes.Xml = function()
2{
3	this.CssClass = 'dp-xml';
4	this.Style =	'.dp-xml .cdata { color: #ff1493; }' +
5					'.dp-xml .tag, .dp-xml .tag-name { color: #069; font-weight: bold; }' +
6					'.dp-xml .attribute { color: red; }' +
7					'.dp-xml .attribute-value { color: blue; }';
8}
9
10dp.sh.Brushes.Xml.prototype	= new dp.sh.Highlighter();
11dp.sh.Brushes.Xml.Aliases	= ['xml', 'xhtml', 'xslt', 'html', 'xhtml'];
12
13dp.sh.Brushes.Xml.prototype.ProcessRegexList = function()
14{
15	function push(array, value)
16	{
17		array[array.length] = value;
18	}
19
20	/* If only there was a way to get index of a group within a match, the whole XML
21	   could be matched with the expression looking something like that:
22
23	   (<!\[CDATA\[\s*.*\s*\]\]>)
24	   | (<!--\s*.*\s*?-->)
25	   | (<)*(\w+)*\s*(\w+)\s*=\s*(".*?"|'.*?'|\w+)(/*>)*
26	   | (</?)(.*?)(/?>)
27	*/
28	var index	= 0;
29	var match	= null;
30	var regex	= null;
31
32	// Match CDATA in the following format <![ ... [ ... ]]>
33	// (\&lt;|<)\!\[[\w\s]*?\[(.|\s)*?\]\](\&gt;|>)
34	this.GetMatches(new RegExp('(\&lt;|<)\\!\\[[\\w\\s]*?\\[(.|\\s)*?\\]\\](\&gt;|>)', 'gm'), 'cdata');
35
36	// Match comments
37	// (\&lt;|<)!--\s*.*?\s*--(\&gt;|>)
38	this.GetMatches(new RegExp('(\&lt;|<)!--\\s*.*?\\s*--(\&gt;|>)', 'gm'), 'comments');
39
40	// Match attributes and their values
41	// (:|\w+)\s*=\s*(".*?"|\'.*?\'|\w+)*
42	regex = new RegExp('([:\\w-\.]+)\\s*=\\s*(".*?"|\'.*?\'|\\w+)*|(\\w+)', 'gm'); // Thanks to Tomi Blinnikka of Yahoo! for fixing namespaces in attributes
43	while((match = regex.exec(this.code)) != null)
44	{
45		if(match[1] == null)
46		{
47			continue;
48		}
49
50		push(this.matches, new dp.sh.Match(match[1], match.index, 'attribute'));
51
52		// if xml is invalid and attribute has no property value, ignore it
53		if(match[2] != undefined)
54		{
55			push(this.matches, new dp.sh.Match(match[2], match.index + match[0].indexOf(match[2]), 'attribute-value'));
56		}
57	}
58
59	// Match opening and closing tag brackets
60	// (\&lt;|<)/*\?*(?!\!)|/*\?*(\&gt;|>)
61	this.GetMatches(new RegExp('(\&lt;|<)/*\\?*(?!\\!)|/*\\?*(\&gt;|>)', 'gm'), 'tag');
62
63	// Match tag names
64	// (\&lt;|<)/*\?*\s*(\w+)
65	regex = new RegExp('(?:\&lt;|<)/*\\?*\\s*([:\\w-\.]+)', 'gm');
66	while((match = regex.exec(this.code)) != null)
67	{
68		push(this.matches, new dp.sh.Match(match[1], match.index + match[0].indexOf(match[1]), 'tag-name'));
69	}
70}
71