Atlas XML Script

A sample of XML script introduced in atlas, and general thoughts and opinions (go ahead and share your own thoughts...)

Atlas introduces a new declarative script format for defining script object instances, their property values, and how they wire up to each other. This has sparked some discussion at as well as some discussion on our internal discussion lists as well. Sounds like this is worthy of a blog post, and sharing thoughts and opinions.

For example, one might define a basic search UI as follows:

<input type="text" id="searchText" />
<input type="button" id="searchButton" />

<script type="text/xml-script">
  <page xmlns="http://schemas.microsoft.com/xml-script/2005">
    <references>
      <add src="ScriptLibrary/Atlas/AtlasUI.js" />
      <add src="ScriptLibrary/Atlas/AtlasControls.js" />
    </references>
    <components>
        <textbox id="searchText" />
        <button id="searchButton">
          <bindings>
            <binding property="enabled"
              dataContext="searchText" dataPath="text.length"
              transform="NumberToBoolean" />
          </bindings>
          <click>
            <!-- Call the invoke method of ServiceMethod when the button is clicked -->
            <invokeMethod target="searchMethod" method="invoke" />
          </click>
        </button>
        <serviceMethod id="searchMethod">
          <bindings>
            <!-- Bind the query field of the parameters property of the
              ServiceMethod to the text property of searchText
              (and keep them in sync) -->
            <binding property="parameters" propertyKey="query"
              dataContext="searchText" dataPath="text" />
          </bindings>
        </serviceMethod>
    </components>
  </page>
</script>

One of the ideas behind this script markup is to allow you to define the behavior of your application and its user interface as a separate layer that is attached to the content and style layers. Sure this can be done in imperative code, but declarative markup has some nice characteristics.

  • First and foremost declarative markup is more designable that code. This approach will facilitate tool development in the future.
  • Second, it is actually simpler for atlas-enabled server controls to emit or render their script-based functionality in the form of markup (similar to HTML markup) using constructs such as XmlTextWriter.
  • Third, declarative markup enables you to specify what the app needs to do, and not necessarily how. Frameworks can capitalize on the ability to interpret semantics and do interesting things - for example imagine running script functionality on the server to generate an initial view of the page, or a view of the page more suitable for search engines.
  • Lastly, it may be simpler to represent simple scenarios where JavaScript code would require script coding, several event handlers to keep all components in sync (in the example, see how the enabled state of the button is keyed off text entry, and is automatically synchronized without having to write a change handler), which is error prone and hard given the lack of mature tools.

I have blogged about declarative programming in a different context in the past. What I believe in is that the code-intensive aspects of the application should be packaged into components that can then be glued together primarily using declarative markup, and perhaps with minimal imperative code. Atlas goes some ways in enabling this, with things like bindings and actions. There are still some key concepts that need to be added to the toolbox to meet the needs for mainline scenarios.

While we have introduced xml script, everything we are doing in atlas is designed to be usable from imperative code as well. In fact, if performance of xml parsing is suboptimal in a particular browser, the server could dynamically convert the xml into the equivalent script on the fly. Components are authored using code, and use atlas building blocks in an imperative fashion. Secondly declarative markup is complementary to script. Both may be used on the same page.

One other thing I should mention (or it is bound to result in some confusion) - I would not expect everyone to have to go out and learn yet another xml format. That is simply not the intent. Server controls can completely provide an abstraction where the familiar server-side programming model is used for development, but server controls under the covers, generate this markup alongside their normal and existing markup rendering.

 

How we came up with this somewhat unconventional or perhaps strange approach?
The goal was put our xml markup inline in the document in such a way that it would be ignored by the HTML parser. This meant we couldn't do something like invent a custom tag, or put into an <xmp> tag or something similar. One thought was to put it in a comment, but that doesn't help find it in code, and secondly, the xml isn't really a comment to begin with. We wanted it to be inline, rather than serving it up via an alternate URL so we wouldn't have to make an async call to the server to retrieve this content, because the page is in an intermediate stage while this script is loaded and processed. Our thoughts turned toward using a comment in regular script. That led to the question of whether script really needed to be JavaScript at all. Experimenting with xml as the format of the script revealed the browser is totally fine with it. Furthermore, the script tag perfectly captures the true semantics. Script component definitions are after all script functionality, but expressed in a markup form. Hence <script type="text/xml-script">. I actually really love the concept...

However, I am really curious to hear the general response, thoughts, and opinions.

Update (9/17): Fixed the sample markup (I forgot the <page> container tag!)

Posted on Friday, 9/16/2005 @ 11:17 AM | #ASP.NET


Comments

22 comments have been posted.

Manish Agrawal

Posted on 9/16/2005 @ 11:54 AM
This is really a good detail.

Nikhil you are a good writter, it will be really helpful if you can provide a Atlas usage guide something exactly like the one which Michael Schwarz created for AJAX.Net(available at : http://ajax.schwarz-interactive.de/download/AjaxGuide.doc). It was so simple and straight. I think that is why it became so popular.

Since it is pretty clear from the above post, most of the problems which surrounded AJAX implementation are smartly dealt with by the Atlas team. An equally Smart Usage document will boost it's usage too.;)

Joshua Flanagan

Posted on 9/16/2005 @ 4:38 PM
I guess I haven't read enough of the "dissenting opinions" yet, but I really like the XML Script solution too. It is very much like the Konfabulator (or Yahoo! Widgets) programming model which I have grown comfortable with. They allow you to create controls using javascript or XML markup. Anything in the XML can be referenced by the javascript. You could create all of your objects using javascript, but the XML declarative approach feels much nicer.

Steve

Posted on 9/16/2005 @ 8:09 PM
I'd still rather be writing C# with objects rather than this declarative approach. I see the value - but as I mentioned before, I went to the .NET model because I could develop web pages with the code behind model. Take your above sample. I'd rather handle the C# onclick and write my search code rather than type <> in html page. This was done with rendering controls - Can we not have the same with C# rendering compliant javascript?

But I do see you writing this:

"One other thing I should mention (or it is bound to result in some confusion) - I would not expect everyone to have to go out and learn yet another xml format. That is simply not the intent. Server controls can completely provide an abstraction where the familiar server-side programming model is used for development, but server controls under the covers, generate this markup alongside their normal and existing markup rendering."

I sign relieve here. In my role I want to be using the controls, by writing C# in my 'code-behind' , but having the flexibility to use these controls on the client-side with callbacks rather than postbacks.

"You could create all of your objects using javascript, but the XML declarative approach feels much nicer." - Can I write about this saying 'why would I do either?' I have this powerful and elegant C# language. Can't we get this to work on the clientside - or output to the client vs. server-side postbacks? I don't want to write javascript, but I must since it runs on the client side for creating Rich internet apps and as above I don't want to learn another xml format.

ie. I have a listbox sorting example - I want to click and drag/sort or even have it with arrows to move items up and down to sort. I don't want a 'autopostback' asp 1.1 technology - it's horrible user experience to move one item wait for a page reload, etc.... So I must wire up listbox.attribute[""] type commands, store values in hiddens, make xmlhttp callbacks, make sure my .net button returns false if not posting back, etc... All a mess in my opinion.

Instead, I want to write my C# in the code behind and tell it to execute the sorting part on the client, and when the user saves, make a callback/postback (again, dev. option). ie. OnClientSelectedIndexChange

To me, that would be very beneficial.

Paul Glavich

Posted on 9/17/2005 @ 3:00 AM
Hi Nikhil,
As I mentioned in my blog post (which you kindly commented on), I did find the declarative syntax a little odd at first, but using it is quite good, and actually is very much in line with standard server side development. You have your list of script references (like assembly references) and associated components that use these libraries, which are also linked to actions via bindings. Nice.
I assume that there will be intellisense provided to assist those who wish to use Atlas via the declarative script? Also, will there be any advantage to defining atlas functionality solely via the declarative model, as opposed to using server controls to provide the declarative markup on your behalf. ie. Will there be things you can *only* do using the declarative script?

Erik Arvidsson

Posted on 9/17/2005 @ 11:54 AM
I reall like that you put the inline XML in a script. It makes much more sense than using an XML or TEXTAREA which has been the usual way to do this since Netscape 4. However the content type should really be application/vnd.microsoft.xml-script+xml. The namespace attribute on the script element is incorrect. The way it is written makes the script element belong to that namespace instead of the XHTML namespace and in that case you might as well call it foobar because the browser has no idea how {http://schemas.microsoft.com/xml-script/2005}script should be treated.

Another question I've been asking is why not XAML is being used here? XAML is simple enough and is designed with UI in mind.

I got a few Atlas comments at http://erik.eae.net/archives/2005/09/15/00.18.07/

Erik Arvidsson

Posted on 9/17/2005 @ 11:55 AM
Haha... should have been XMP or TEXTAREA.

Nikhil Kothari

Posted on 9/17/2005 @ 12:45 PM
Erik, I had a mistake in the sample - I missed out the <page> tag, and have updated it. The xmlns goes on the page tag, where it defines the xml namespaces in use within the script markup. I realized my mistake when I saw your comment above about namespace.

Regarding content type, I like the simplicity of text/xml-script (which I'd hate to loose), but I agree we should check if there is a standard way of defining a new one.

Also, I forgot to mention - we did think of the XML tag - but that is not supported cross-browser. Browsers other than IE would treat it as content which would go against our requirements.

Paul, we will have intellisense eventually. We'll need to figure out the scenarios of declarative script vs. server controls vs. co-existence of both.

Steve, I agree it would be nice programming with C# and never have to do JavaScript. However, someone does need to implement something in JavaScript, package it up for the rest who would not need to think about it. Also there is a case to be made about keeping UI logic as close to the UI as possible. Callbacks enable you to go back to the server, but at a cost (abstraction, state transfer, incurring a HTTP connection, etc. etc.). In order to keep UI logic on the client then, you do need to do some scripting. Yes, it would be nice to see improvements in scripting itself. Atlas is a first step in that direction by improving how scripting is approached in general.

Its good to see all this discussion!

Chris Kennedy

Posted on 9/19/2005 @ 7:37 AM
Why use XML??? Now you will have to have a JavaScript xml-script engine to be cross browser compatible... Unless I'm missing something here and that script tag is supposed to have runat="server" on it so that the server converts xml-script to JavaScript for the browser. Besides, I believe XML is horribly overused. (When you only have a hammer, everything looks like a nail and all that.) Also, I don't want my script embedded in my XHTML page. We finally got rid of inline style (font tags and such), so why would we want inline script???

JavaScript is so close to C/C# that crossing between the two is rather painless. Better support for JavaScript in VS.NET would go a long ways toward improved programmer productivity. Intellisense in .js files is horrid to non-existant. Fix the tools instead of creating new languages. (I know the new languages are sexier, but if the tools are broke, it doesn't matter what you do with language design.)

Nikhil Kothari

Posted on 9/19/2005 @ 9:41 AM
Chris - as I mentioned the goals is to make this designable, do more things with it (eg. process it on the server) etc. Having this be in xml, or in some declarative form (xml is not the only one, but a more common one, that happens to have some nice characteristics) rather than imperative form enables such things.

I don't see why you care about how this appears in the browser - inline or as a reference. I think what people should be concerned about is development methodology. For example, if you want to separate it at development time, thats great, and should be enabled. Who cares how the browser gets the bits - as a single URL or a set of multiple URLs. That should be driven based on performance and deployment requirements. If having it inline gives the best runtime behavior, then so be it - the tools on the server should take care of generating that from separate bits. I think some people are overly obsessive with what they see with View Source. What they should see is the source they have in their project back on the server. This is true of script, styles, and everything else...

Better support for JavaScript is required - lots has been said about that (in other posts on this blog as well). I don't think anyone will disagree. But as mentioned the goals for introducing this are more than just providing an alternative to imperative programming. As I mention, actual coding is not going to disappear - it is what brings components into existence.

Rishi

Posted on 9/25/2005 @ 8:33 AM
Just wanted to share my thoughts on Atlas and it'z design model:
- The single biggest thorn I have with the Atlas model is that it largely forces one to use webservices for practically any data related operations, this model of doing adds to workload (and aslo enlarges the scope of the application), in addition to the client-side framework one must use!! Which to me personally is a big no-no!
- Secondly, I personally think the atlas mode should be more server-side oriented and thereby make the atlas script more aligned with the asp.net scripting! Infact, maybe you can shed some light on why rather than a "onClick" attribute we have "<Click>" element? Wouldn't it be better and easier to work with asp.net type scripts with some dotted notions for the client side also?
- Thirdly, this more of a suggestion wouln't it be better to make your atlas script work better with Callback framework in asp.net 2?? Like making use of the shorted page lifecycle??

Ulf

Posted on 9/27/2005 @ 3:10 AM
Nikhil, why are you not answering the questions concerning AJAX .NET lib? I see no difference between AJAX .NET and ATLAS. The new stuff with the XML script is very bad because we have to learn this new XML syntax and JavaScript to build new controls. Is there any statement about the difference between these two libraries? And, will ATLAS be available to .NET 1.x?

Jon Henning

Posted on 9/27/2005 @ 1:26 PM
"I don't see why you care about how this appears in the browser - inline or as a reference."

Performance. Why send down the same XML with each page request, when it could be cached in a separate file. Like Chris mentions, we have been here before with inline styles. We have also been here before with inline script. If it is static, put it in a file that can be cached after the first load.

I found it interesting that the statement at PDC was made to go the JSON route instead of XML for webservices since the payload was smaller, which for the most part I can agree with. Yet when we can go the javascript natively for our scripting, a way to write XML for the script is invented... I find this mentality bizarre...

Nikhil Kothari

Posted on 9/28/2005 @ 2:47 PM
Rishi:
We support WebMethods both in asmx web services, and in pages. For pages we use callback-like model. As we build up atlas, we will be using both web services and callbacks. Also callbacks will be unified to be an integral part of atlas.
onClick vs. Click - The Click you see in the example is a declarative way to associate work with an event. You can also write click="myHandler". "Click" is the actual name of the event hence that is used directly (similar to XAML)

Ulf:
As I wrote in my post, I don't expect everyone needs to go out and learn XML script. It is a markup format suitable for server controls to target, and for tools. But it is designed such that its human readable as well. Also I don't expect everyone to have to learn JavaScript - however if you want to write truly client-side apps, then you need script - either you have to write it, or use a component that encapsulates it - there is simply no shortcut. Atlas is both about enriching experiences, as well as enabling those component developers to actually encapsulate script behavior. This way only the component developer needs to author script, and each app developer does not need to be a script expert.
Regarding ajax.net, I am not sure which question you are referring to. Atlas also provides the ability to use it to communicate with the server asynchronously, and update the UI using dhtml directly.

Jon:
As I mentioned, one of the ideas behind choosing this xml approach, is that we can actually do interesting things with it on the server. For example if perf is bad, we could convert it into equivalent script. Its not completely straightforward hence its not been done yet. However, everything that the script parser is doing can be done directly in code. The other point is its not necessarily static. It may be different for each request.

Steve

Posted on 9/28/2005 @ 5:37 PM
Interesting Nikhil. I do understand what you are saying. Rishi makes an interesting point that I myself also have wondered:

"Secondly, I personally think the atlas mode should be more server-side oriented and thereby make the atlas script more aligned with the asp.net scripting! Infact, maybe you can shed some light on why rather than a "onClick" attribute we have "<Click>" element? Wouldn't it be better and easier to work with asp.net type scripts with some dotted notions for the client side also?"

What I picture here is: you drag your 'Atlas' button to the page - goto the events - similiar to button now, write C# code - ie. bind data to your 'Atlas' gridview with C# code. However it all is rendered client side. The 'Atlas' button property is set to 'client side' rather than 'server side', also the Grid supports all the same OnDataBound calls with templates, etc...

Most the needs I have personally when it comes to client side vs. asp.net server side are is eliminating the postbacks. Sure, a postback on a form submit is natural, but to have a postback on a dropdown selectedIndexChanged is not.

Where I picture Altas really benefiting the ASP.NET developer is that we can have the same dropdown which behaves very similiarly except it eliminates the need for the postback, with Altas abstracting away the callback.

I am hoping this is the direction Atlas will take - as a ASP.NET developer from day one, my only complaint has been the round trips to the server - otherwise the model is excellent.

Nikhil Kothari

Posted on 9/28/2005 @ 7:52 PM
Steve, I honestly want to have a discussion on this... and while weblog comments don't work out to be the best mechanism, lets see how it goes.

First, I understand where you come from. My question in response would be what do you do in your SelectedIndexChanged handler (lets assume the event fires via a callback mechanism instead of a postback)? Do you change just the drop-down? I'd be willing to bet you change other controls on the page. For example, you might use the new selected option to apply a new filter on a data source, which then has the rippling effect of changing the contents of some data-bound controls. So therein lies the problem - you pretty much have to render all the page. At the very least you are returning generated html, and that html needs to be inserted into the right portions in the tree, and old html needs to be taken out. This is even more complex if you think about the scenarios where just this partial re-rendering also needs to update some style rules etc. Still more complex is to figure out what portion of state has changed during the callback, so as to merge it with the overall state, so that the state management feature can do its job as expected when a true post-back does occur. So the challenge is its near impossible for a generic framework to let an imperative opaque block of server-side app code handle an event, and guess in a reasonable and robust way as to what to do in response on the client. While you can eliminate the post-back (thats the easy part), the post-back-like semantics of the app cannot be eliminated while preserving the same server control model.

The only way you truly get to make an app interactive is to move UI processing to the client. From various comments I've been seeing, and thinking about how atlas is really different from various other frameworks, I think I need to post a bit about this overall model in terms of why and what scenarios are enabled by taking the steps to move UI interaction logic to the client. That might help foster some of this discussion.

Steve

Posted on 9/30/2005 @ 4:35 AM
Thanks Nikhil. I will await this, I think it would help.

Not saying this is the perfect senario - but have you seen what Dart has done with their controls: http://www.dart.com/powerweb/livecontrols.asp ?

These set of controls work with each other so the effect of one control on another can occur. The part that is interesting is that you write your .NET code in the handlers just as if they are normal server side controls.

That aside, I do understand this complexity, as I worked on a custom callback framework in 1.1 where I would be rendering the controls on the callback, and as you suggest, as the complexity grew, so did the amount of javascript :) Not only would I have the datagrid rendering, I would have the controls inside the templates invoking callbacks as well. Also, multiple controls on a page - each interacting with each other via callbacks - and re-rending. The framework is very similiar to the one in asp 2.0. My issues came about when rendering these controls within ascx controls that were loaded dynamically with properties set on a master aspx page. (think ibuyspy with callbacks).

Again, I do like what I see with the Atlas, I am looking to see how it will change my current way of programming. I'd like to see these controls span across the other systems, such as Sharepoint, MCMS, etc... so that it will present a unified rich internet application.

Ron Buckton

Posted on 11/4/2005 @ 5:03 PM
Although this post is a month past due I thought I'd add to the discussion. I spoke with Shanku at PDC about some of the futures for Atlas and one of the things he mentioned was the future of client and server development and the possiblity of generating JS from the server side.

I've been working on a project that isn't directly related to this, namely reproducing some of the features of LINQ in the current RTM of .NET 2.0 (without the LINQ compiler). The relevant part of the project to this discussion is my work building a Lambda Expression Tree at runtime by reflecting against a delegate and using MethodBase.GetMethodBody() and the MSIL available from that method. I am currently able to convert complex MSIL (as long as it results in a single expression) and convert it into an object model which is then used to generate TSQL. Such a model can be extended to support an object model like a standard AST and use that to generate javascript as long as the C# (or other language) code is very specific.

I'll hopefully be blogging all of my source code at some point in the next month once i move my blog (And my company's site) to the production server.

Fatih Sahin

Posted on 2/21/2006 @ 6:17 PM
As a beginner to Atlas,

First I met Ajax.Net before Atlas..I think what most frightens me about Ajax.Net is the callback functions in the script. For example when i return a custom type from a function in a Web Service to the callback, it seems still hard to populate a template and display the results.

Atlas is better because it has declarative xml script which makes data-bindings easier and more importantly it has server side controls which is automatically rendered.

I liked mostly these UpdatePanels.. they are cool

But there should be more resources on the net.. and developers need to learn Atlas vision. What is the aim of Atlas? Will it grow and develop continually?
Or maybe will 2007 be too late for Atlas to learn because it is already disposed? Will Microsoft insist and give support for the Atlas infrastructure? I think this point is really important for beginners to Atlas.

Richard Collette

Posted on 2/28/2006 @ 3:18 PM
Two questions..

Is the xml-script compatible with all browsers? If so, how is this (currently) proprietary scripting language interpreted by non ie browsers?

Second, regarding determination of client side changes. Years ago I worked with a VT terminal software package that buffered screens, sending only the necessary commands to update a screen to the terminal. Those commands might involve:

Cursor movements and character replacement.
Quadrant clear and redraw
Whole screen redraw

depending on how much and what was being changed. Is that not possible with HTML as well, where a DOM/document is buffered, changed on the server and then only the DOM changes are returned to the browser to be updated by a small piece of local script. A reset button would redraw the whole screen if it got out of sync. Without something like this, it seems like developers are constantly going to have to write application specific client UI coordination code.

Devang

Posted on 3/27/2006 @ 9:27 PM
I want to show an image when user hovers over an item,but that items are random on page, i want to write such code that whenever such item is shown on the page its mouse hover is enabled.i.e the items are dynamic in nature,i think declarative sysntax doen't solve my purpose as i have to specify the id of each item(which unfortunatly i don't know) in advance. This is what i felt on using it..please correct me if am wrong

so help me how could i solve this..

Rajiv

Posted on 6/14/2006 @ 10:11 AM
Please provide us Atlas usage guide

Thanks..

terraslate

Posted on 6/28/2006 @ 10:24 AM
don't you think your efforts would be better spent integrating the clr into other browsers as a plugin? purchase a little trust from the other browser makers, get the plugin installed automatically, and let us just use xaml and remoting to work with the server. if this is the future of computing then we are all in the wrong job. you are throwing bad code after worse code. this isn't an asp.net tream issue. this is an corporate issue of internet stakeholding between microsoft, opera, firefox and other browser makers. the fact that all your browsers don't present an advanced platform architecture like the clr is the actual problem. instead - wait for it - you present the world with.....JAVASCRIPT. Hooray!!! The sum total of years of internet wars amounts to javascript and you are writing this gumpf and sticking it to us like its the holy grail of computing. the computing industry should be ashamed of itself. i really can't wait for the bio age to wipe this silicon waste from our planet. can you imagine genetic computers running javascript - they would if the likes of these monolithic industry players had anything to do with it. i can see the headlines now: bio-bot - powered by javascript. nice.
The discussion on this post has been closed. Please use my contact form to provide comments.