views:

537

answers:

2
+2  Q: 

CAML to HTML

I'm invoking one of SharePoint's web service APIs that returns a CAML fragment. I've searched the interweb far and wide but I've been unable to figure out how to make this CAML fragment to render as "normal" HTML that I can render in a more sane environment like Plumtree, WLP, Liferay or any other portal besides SharePoint.

Without a way to do this, I'm wondering why Micro$oft wrote SharePoint web service calls that return CAML in the first place. Web services are for interoperability and it seems the CAML is only valid within a WebPart running within SharePoint. [Note to Bill and Steve: that's not interoperability.]

If I can't do anything with the CAML that comes back, I'm just going to call a different web service that returns only data and then write my own UI. I was hoping for an easier path. Any suggestions would be greatly appreciated.

+3  A: 

You could send the CAML through an XSLT stylesheet to generate HTML or XHTML.

Edit:

Considering your first question (why SharePoint returns CAML from some of its web services)... who knows? It may be there to support authoring tools such as SharePoint designer. But it seems clear from the dearth of documentation and tools that CAML is a more-or-less internal SharePoint thing. At present, performing CAML-to-HTML conversion would require either somehow accessing the CAML rendering engine within SharePoint, or re-implementing it. Neither option is attractive.

I think that your conclusion (calling data-returning web services and rendering the HTML yourself) is probably your best bet.

Paul Lalonde
I could also just stick a fork in my eye, but what good would that do?
bucchere
Thanks for the edit -- doing our own rendering looks like the path we're going to pursue. I thought about trying to use SharePoint's ISAPI filter somehow to do the CAML parsing/rendering for me, but I'd rather just write some UI rather than try to hack their engine.
bucchere
+5  A: 

The CAML is still XML and as mentioned, XSLT will be able to render it as HTML. The actual gnraly nested OR/AND structure of CAML is a whole nother issue.

That would require unrolling the CAML structure and displaying it in a way that normal people understand.

Unfortunately, the XSLT language is unsuitable for unrolling nested structures like this (it has no stack). It is possible, but having done it I recommend strongly using another language to parse and unroll the CAML.

I have yet to see a CAML to SQL conversion code. Sounds like a great Codeplex project.

So in summary... you are a bit stuffed with CAML. While it is XML, it's structure is unsuited to use in any other query language.

Nat
Trying to write an XSLT to render the CAML as HTML sounds more painful than just writing a UI on top of a standard (i.e. non-CAML) XML (as I mention in the last paragraph of my question). What exactly is the point of CAML or does it solely exist to frustrate developers?
bucchere
I can only imagine that the person who created it thought there was a point i.e. we need a query language that is xml. After all, XML is like violence, if it does not solve your problems your are not using enough of it. But at the end of the day all CAML actually does is frustrate the us developers.
Nat