Web sites, Objects & XML ....... WTF?

Status
Not open for further replies.

kleel

Ars Scholae Palatinae
1,022
Hi,

Presuming that you are designing an application layer's objects (COM or Java it doesn't matter) which are going to
send data back to a presentation layer (ASP/JSP etc)

Is it a good idea to send all the data back in the form of XML? and maybe shape it into whatever using XSL?

Or is this just extra work (by the objects) that isn't really needed? and therefore be ignored .....

I'm a bit confused and need to know if this is the way I _should_ be designing my objects or not. Is this considered good OO practice these days??? (I'm a bit rusty :( )

Thinking about it I wonder if it is .. unless you are coding a site which is going to be viewed by different viewers/browsers (i.e WAP, HTML etc) then surely there isn't much point?

Kleel
 

ak6ar

Seniorius Lurkius
34
It all depends on what the objects are being used for, how large are the datasets you are returning, and what are the requirements for the API you are creating?

Let me give you an example. If the data you are returning is going to be used as primarily display items on the web, it is probably better to pass back XML, and use XSL to display it.

If on the other hand the type of data you are returning are results that are then manipulated, or used to form other data on the web, then this may not be optimal.

Also if the data you are returning is manipulated and returned back to you (in a second call let's say) then you don't want to have one format for data coming to you and a different format to data being returned.

I think it's usually a good idea to start coding to standards, as it makes it easier on whomever ends up maintaining this application.

Oh yes if the web is acting as a pass through to calls to your application (from some remote application), then you should definitely look into SOAP and Webservices.
 

Qom-Riyadh

Seniorius Lurkius
31
Having done this on a previous project, I would say that XML / XSLT transformations are overkill if the data is never leaving your own domain (ie, you're not providing an XML 'feed' to another application). XSLT is a horrible, horrible nightmare, and you are probably going to have to do the transformation on your own server (Cocoon) if you want to support many browsers (wireless comes to mind). You are way better off using a good, fast template engine (Velocity), and defining multiple templates if you need to (ie. WML, HTML).

If XML looks like a good choice, I would still try to stay away from XSLT unless you have more propellerheads than you know what to do with. AxKit comes to mind, but I havn't used it myself (it uses embedded perl / xpath for transformations).

Whatever you decide, it's definately a good idea to separate your presentation from your business logic. Embedded HTML == the poo.
 

kleel

Ars Scholae Palatinae
1,022
Thanks for the response ....

I was just wondering if it was a good idea or not .... I think I will go for it as an coding exercise if nothing else (ASP & VBCOM)

Qom-Riyadh - it's interesting that you think XSL coding is a nightmare .. I'm no expert but it seems like you can run into brick walls quite easily .. i.e. page not displaying at all if there is a bug. XML-Spy might be a necessary purchase.

Here is another (kinda related) question ...
Say you have object1 returning some xml and another object (object2) returning even more xml ... how do you combine the two with xsl?
do you have to have 2 XSL transforms and combine the output returning that to the browser? or is there another way?
 

Qom-Riyadh

Seniorius Lurkius
31
My big problem with XSLT is that it is written in XML, and has all the limitations you can imagine of a programming language written in a markup language. For starters, it is incredibly verbose. A simple conditional looks like:
code:<HR>
Code:
<xsl:if test=boolean expression>
    ...
</xsl:if>
Yowza. My hands hurt already.

XSLT is also very non-linear. It's all about recursion and pattern matching, and I found it very difficult to keep track of what was going on once I was more than a few levels deep.

This is my experience with XSLT, and though I've heard similar stories from other developers, I'm sure that some people will argue with me. If you have the time, I'd give it a try to see how it works for you.

If you want a good example of how something seemingly simple can get really complicated, try this exercise.

Transform this XML into HTML:
code:<HR>
Code:
<document>
  <paragraph>
    This is a <link href="mysite.com">link</link> to another document.
  </paragraph>
</document>

edit: fixed my code :)
 
Status
Not open for further replies.