Simple XML output for IBF Webservices

Posts   
 
    
IBF_Mike
User
Posts: 3
Joined: 13-May-2005
# Posted on: 13-May-2005 12:01:59   

Hi Guys,

I have to say I love LLBLGen. I have used it for one project now, but I like to use it on the next as well. My next project is based on IBF (Infromation Bridge Framework). IBF relies on XML and webservices.

When I follow the guidelines of Microsoft IBF development guide on http://www.microsoft.com/technet/itsolutions/cits/iwp/ibf/soldev/moibf1_sdg_08.mspx, I have to create xml classes for each of my entities. Luckily LLBLGen build these for me. Unfortunately the xml generated with LLBLGen is much to complex. Is it possible to generate a simple xml variant.

LLBLGen output:

<CustomerEntity CustomerID="1"> <ObjectID>a21d5b32-a843-4365-9b30-d9506b67ad81</ObjectID> <IsNew>False</IsNew> <Fields> <CustomerID> <CurrentValue>1</CurrentValue> <DbValue>1</DbValue> <IsChanged>False</IsChanged> <IsNull>False</IsNull> </CustomerID> </Fields> <IsDirty>False</IsDirty> <EntityState>Fetched</EntityState> <SavedFieldSets /> </CustomerEntity>

Wanted output:

<?xml version="1.0" ?> <Customer xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="Customer-Data"> <CustomerID>1</CustomerID> </Customer>

Possible solution is building an extra entityclass

[XmlRoot("Customer",Namespace="Customer-Data",IsNullable=false)] [XmlType("Customer", Namespace="Customer-Data")] public class Customer { private int _CustomerID;

[XmlElement] public int CustomerID { get{return this._CustomerID;} set{this._CustomerID = value;} } }

Copy all fields and serialize the extra entityclass

IBFDemo.EntityClasses.CustomerEntity customerEntity; customerEntity = new IBFDemo.EntityClasses.CustomerEntity(1);

Customer customer = new Customer(); customer.CustomerID = customerEntity.CustomerID;

System.Xml.Serialization.XmlSerializer serialize = new System.Xml.Serialization.XmlSerializer(typeof(Customer)); serialize.Serialize(Response.OutputStream, customer); Response.End();

I don’t like this solution cause it generates to much work. I just want to use the LLBLGen classes and give a correct an simple xml output.

Mike

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 13-May-2005 12:30:45   

The thing with even more compact XML is that it loses information required for a roundtrip. For one-way data, it can be even more compact though. You then have to consider that an entity passed back in that very compact xml loses change tracking for example.

What I had in mind when I wrote the compact version of the XML output was that it would be very easy to setup an XSLT to convert the xml for various compact versions. Though is that sufficient for you?

Frans Bouma | Lead developer LLBLGen Pro
IBF_Mike
User
Posts: 3
Joined: 13-May-2005
# Posted on: 13-May-2005 13:04:29   

I am aware that some information will be lost with a roundtrip. At the moment we just want to display data in the task pane of IBF. We use IBF to subtract some data of several Backends like ERP, CRM and display it in one single screen to the user. This user can get the information concerning a customer and generate a custom letter/mail with standard text blocks.

An XSLT could be a solution, but the question remains how much code we have to right. Do we need a separate XSLT for each entity or can think of way to generate compact xml for each entity.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 13-May-2005 13:44:00   

IBF_Mike wrote:

I am aware that some information will be lost with a roundtrip. At the moment we just want to display data in the task pane of IBF. We use IBF to subtract some data of several Backends like ERP, CRM and display it in one single screen to the user. This user can get the information concerning a customer and generate a custom letter/mail with standard text blocks.

An XSLT could be a solution, but the question remains how much code we have to right. Do we need a separate XSLT for each entity or can think of way to generate compact xml for each entity.

It should be just 1 XSLT. As teh XML is build up like this:


<OrderDetailsEntity OrderId="10289" ProductId="3">
    <EntityReference PropertyName="Products"/>
    <ObjectID>4f876197-c266-4613-8f6a-6c3ca343ff8a</ObjectID>
    <IsNew>False</IsNew>
        <Fields>
            <OrderId>
                <CurrentValue>10289</CurrentValue>
                <DbValue>10289</DbValue>
                <IsChanged>False</IsChanged>
                <IsNull>False</IsNull>
            </OrderId>
            <ProductId>
                <CurrentValue>3</CurrentValue>
                <DbValue>3</DbValue>
                <IsChanged>False</IsChanged>
                <IsNull>False</IsNull>
            </ProductId>

You'll see you can grab all elements from the Fields node, and for the values for these fields, you can use CurrentValue's value.

My XSLT is a bit rusty, but it should be possible.

Another thing to think about is using typedlists/dyn. lists if the data is one-way only. These are data-tables, perhaps the datatable/set xml is better consumable by your code?

Frans Bouma | Lead developer LLBLGen Pro
IBF_Mike
User
Posts: 3
Joined: 13-May-2005
# Posted on: 13-May-2005 14:32:06   

Thnx for the suggestions you sent.

I’ll try to create an XSLT for transforming the generated XML. Besides the XSLT I’ll look at the typedlists as well.

My upcoming posts will contain information about possible solutions. I don’t know when, but I hope soon.