Our approach is to implement one class for each RDL object which "knows" how
to serialize and deserialize itself. Then, when you serialize the master
report object, the whole hierarchy is serialized. I believe this is pretty
much what the internal RDL object in the Report Designer does as well. This
is what the implementation for the Field object may look like:
using System;
using System.Xml;
using System.Xml.Serialization;
namespace Reporting.ObjectModel
{
/// <summary>
/// Contains information about a field within the data model of the report.
/// </summary>
public class Field : IXmlSerializable
{
#region Constants
internal enum StandardFieldNames
{
Item,
Entity
}
#endregion
#region Private Variables
private string _name;
private string _dataField;
private Value _value;
private Type _typeName;
#endregion
/// <summary>
/// Creates an instance of a Field.
/// </summary>
public Field(){}
/// <summary>
/// Creates an instance of a Field and sets its state.
/// </summary>
public Field(string name, string dataField, Type type)
{
_name = name;
_dataField = dataField;
_typeName = type;
}
#region Public Properties
/// <summary>
/// Name to use for the field within the report.
/// </summary>
public string Name
{
get {return _name;}
set {_name = value;}
}
/// <summary>
/// Name of the field in the query.
/// </summary>
public string DataField
{
get {return _dataField;}
set {_dataField = value;}
}
/// <summary>
/// An expression that evaluates to the value of this field.
/// </summary>
public Value Value
{
get
{
if (_value == null)
_value = new Value();
return _value;
}
set {_value = value;}
}
/// <summary>
/// An expression that evaluates to the value of this field.
/// </summary>
public Type TypeName
{
get
{
return _typeName;
}
set { this._typeName = value; }
}
#endregion
#region IXmlSerializable Members
/// <summary>
/// Converts a Field into its RDL representation .
/// </summary>
/// <param name="writer">The <typeparamref name="XmlWriter"/> stream to
which the Field is serialized.</param>
public void WriteXml(XmlWriter writer)
{
//--- Field
writer.WriteStartElement(Rdl.FIELD);
writer.WriteAttributeString(Rdl.NAME, _name);
//--- DataField
if (_dataField != null)
writer.WriteElementString(Rdl.DATAFIELD, _dataField);
//--- TypeName
if (_typeName != null)
writer.WriteElementString("rd:TypeName", _typeName.ToString());
//--- Value
if (_value != null)
((IXmlSerializable)_value).WriteXml(writer);
writer.WriteEndElement();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
/// <summary>
/// Generates an Field from its RDL representation.
/// </summary>
/// <param name="reader">The <typeparamref name="XmlReader"/> stream from
which the Field is deserialized</param>
public void ReadXml(XmlReader reader)
{
if (reader.AttributeCount > 0)
_name = reader[Rdl.NAME];
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.EndElement && reader.Name == Rdl.FIELD)
{
break;
}
else if (reader.NodeType == XmlNodeType.Element)
{
//--- DataField
if (reader.Name == Rdl.DATAFIELD)
_dataField = reader.ReadString();
//--- Value
if (reader.Name == Rdl.VALUE)
{
if (_value == null)
_value = new Value();
((IXmlSerializable)_value).ReadXml(reader);
}
}
}
}
#endregion
}
}
--
HTH,
----------------------------------------------
Teo Lachev, MVP, MCSD, MCT
"Microsoft Reporting Services in Action"
"Applied Microsoft Analysis Services 2005"
Home page and blog:
http://www.prologika.com/ -------------------------------------------------
[quoted text, click to view] "brianpmccullough" <bmccullough11@comcast.net> wrote in message
news:DB5F562C-E889-4A55-99E6-48B12CF5664E@microsoft.com...
> Teo,
>
> Thanks again for the help!!!
>
> I did try creating an object model on top of the RDL objects, basically I
> was sending in an xmlnode to each object and then the properties were
> going
> to going to reference the node InnerText and attribute values.
>
> For example:
>
> Public Class SortBy
> Public Sub New(ByVal node As XmlNode)
> End Sub
>
> Public Property SortExpression As String
> Get
> Return me._node.SelectSingleNode("SortExpression").InnerText
> End Get
> Set (ByVal value As String)
> me._node.SelectSingleNode("SortExpression").InnerText = value
> End Set
>
> End Class
>
> I got discouraged when I realized I was going to have to pass around a
> namespace manager reference to everything when I needed to XPath query
> some
> of the nodes that I didn't need a complete object model for...
>
> This was the only way I saw to do it so that I wouldn't have to
> reserialize
> things back into RDL (xml).
>
> Since my RDL manipulation was limited to setting the visible properties on
> existing group headers and footers, clearing and inserting sortby
> elements,
> setting the commandtext for a dataset and a few minor formatting items, i
> just ended up creating a really simple RdlReport object that exposed some
> methods to take care of this...
>
> How did you handle the serialization of your RDL object model?
>
> Thanks
>
> -Brian
>
> "Teo Lachev [MVP]" wrote:
>
>> > Out of curiousity, have you seen or heard of a Reporting Services
>> > solution
>> > in which "template" rdl files are created and then sorting, grouping
>> > (including counts/sums/page breaks), filtering are all configurable by
>> > users?
>>
>> Sounds familiar :-) We are creating an ad hoc designer right now in hope
>> that the RS team will provide an reusable WYSWYG designer in RS 2007(?).
>> Based on my experience, if you need to do a lot of RDL manipulation, what
>> I
>> would recommend is you build an object model on top of it. Creating
>> objects
>> for all RDL elements is tedious and will take some time but it really
>> pays
>> off in a long run because you don't have to use the XML DOM API. It
>> worked
>> great for us.
>>
>> --
>> HTH,
>> ----------------------------------------------
>> Teo Lachev, MVP, MCSD, MCT
>> "Microsoft Reporting Services in Action"
>> "Applied Microsoft Analysis Services 2005"
>> Home page and blog:
http://www.prologika.com/ >>
>> -------------------------------------------------
>> "brianpmccullough" <bmccullough11@comcast.net> wrote in message
>> news:1C12E90C-BC5B-4C2C-B813-193F5681CA84@microsoft.com...
>> > Thanks Teo...I kinda gathered that after carefully reading the
>> > documentation
>> > on the PageBreakAtEnd element.
>> >
>> > Out of curiousity, have you seen or heard of a Reporting Services
>> > solution