1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Views
.Brail
17 using System
.Collections
;
22 public class XmlExtension
: IDslLanguageExtension
24 private readonly TextWriter output
= null;
25 private readonly XmlWriter writer
;
27 public XmlExtension(TextWriter output
)
30 writer
= XmlWriter
.Create(this.output
);
33 public TextWriter Output
35 get { return output; }
38 #region IDslLanguageExtension Members
40 public void Tag(string name
)
42 BlockTag(name
, null, null);
45 public void Tag(string name
, ICallable block
)
47 BlockTag(name
, null, block
);
50 public void Tag(string name
, IDictionary attributes
, ICallable block
)
52 BlockTag(name
, attributes
, block
);
62 public void text(string text
)
64 writer
.WriteString(text
);
67 private void BlockTag(string tag
, IDictionary attributes
, ICallable block
)
69 writer
.WriteStartElement(tag
);
71 if (null != attributes
)
73 foreach(DictionaryEntry entry
in attributes
)
75 writer
.WriteAttributeString((string) entry
.Key
, (string) entry
.Value
);
83 writer
.WriteEndElement();