what I am having now is:

public class XmlPrettyPrintFilter : TransformFilter
    {
        private bool contentComplete;
        private readonly StringBuilder content;

        public XmlPrettyPrintFilter(Stream baseStream)
            : base(baseStream)
        {
            contentComplete = false;
            content = new StringBuilder();
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            content.Append(buffer.ConvertToString());
            contentComplete = buffer.Length < 28672;
            if (!contentComplete) return;
            var b = prettyPrint(content.ToString()).ConvertToByteArray();
            BaseStream.Write(b, 0, b.Length);
        }

        private static string prettyPrint(string s)
        {
            var document = new XmlDocument();
            document.LoadXml(s);

            string xml;
            var xmlReader = new XmlNodeReader(document);
            using (var stringWriter = new StringWriter())
            {
                var xmlWriter = new XmlTextWriter(stringWriter)
                                    {
                                        Formatting = Formatting.Indented,
                                        Indentation = 1,
                                        IndentChar = '\t'
                                    };
                xmlWriter.WriteNode(xmlReader, true);
                xml = stringWriter.ToString();
            }
            return xml;
        }
    }

it seems to work well. probably throws when the view is not valid xml, which
is kind of a good thing.
still that is hackish and should only be used during development, I suppose.
Any ideas of how to make this better are very welcome.

On Fri, Nov 14, 2008 at 3:36 PM, Jan Limpens <[EMAIL PROTECTED]> wrote:

> That's exactly where I am right now, but content does not come all in one
> piece, so I have to find somehow, when the last batch arrived. Then I can
> apply the transformation and write it back to the stream...
>
>
> On Fri, Nov 14, 2008 at 3:33 PM, Ken Egozi <[EMAIL PROTECTED]> wrote:
>
>> take a look at TransformFilters  (and ViewFilters in AspView)
>>
>>
>> On Fri, Nov 14, 2008 at 7:30 PM, Jan Limpens <[EMAIL PROTECTED]>wrote:
>>
>>> hi,
>>>
>>> I want to apply an xslt transformation to controller actions that return
>>> xml. a filter would be ideal for this
>>> but it seems that content comes in batches via the buffer, so i must wait
>>> for the whole content to have arrived ta make the transformation. is there a
>>> simple method for this?
>>>
>>> i thought about caching the buffer in a stringbuilder, memorystream or
>>> something alike that and conclude, that if current buffer's length is
>>> smaller than whatever the batch size seems to be, I apply the transform. but
>>> that seems terribly hackish to me...
>>>
>>> --
>>> Jan
>>> ___________________
>>> [EMAIL PROTECTED]
>>> www.limpens.com
>>> +55 (11) 3082-1087
>>> +55 (11) 3097-8339
>>>
>>>
>>>
>>
>>
>> --
>> Ken Egozi.
>> http://www.kenegozi.com/blog
>> http://www.musicglue.com
>> http://www.castleproject.org
>> http://www.gotfriends.co.il
>>
>> >>
>>
>
>
> --
> Jan
> ___________________
> [EMAIL PROTECTED]
> www.limpens.com
> +55 (11) 3082-1087
> +55 (11) 3097-8339
>



-- 
Jan
___________________
[EMAIL PROTECTED]
www.limpens.com
+55 (11) 3082-1087
+55 (11) 3097-8339

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to