Wednesday, November 19, 2008

xml data encoding issue in sql server 2005

Today I found one of my friend is struggling with saving xml to sql server 2005 database with Norwegian characters. When he try to insert xml data error is throwing saying "invalid characters found in line number ....". According to the definitions sql server keeps xml data using utf-16 encoding. so this should support Norwegian characters. The xml document which we are trying to save contains the declarations as

<?xml version="1.0" encoding="utf-8" ?>

If we remove the above xml declaration from the xml document before sending it to sql server, it will be automatically handled by the server using utf-16. you can use .Net to remove the declaration before sending it to server and insert declaration while you retrieve xml from database.

Monday, November 17, 2008

Cairngorm with Flex

Cairngorm is a framework which facilitates to write well structured flex code with MVC architecture. Its Front controller, Model Locator, command and delegate patterns are the main components of the framework. I will try to explain how it works with a simple example application of user search.

  1. App boots up, shows first state
  2. user types in some keywords, clicks the Search button
  3. this fires the doSearch event handler
  4. the doSearch handler creates a CairngormEvent, and dispatches it
  5. the Controller has mapped that type of event to a Command, and thus it runs the command, passing it the event
  6. the Command looks at the event type in the execute function and
    decides what to run, in this case, searchBooks, passing the event’s
    data to the function
  7. search books creates the Business Delegate, and calls its method
  8. the Delegate gets the WebService from the ServiceLocator, fires off the WebService, and waits for a response
  9. if the response is successful, it parses the E4X XML via a Factory to a list of Book ValueObjects
  10. finally, it calls the responder’s onResult function
  11. Since the Command is the Responder, he gets the data, and sets it to the ModelLocator and updates the applications state
  12. The View’s are bound to the state variable and book list in the ModelLocator, so they immediately have their bindings fire
  13. This causes the main app to change state, and show the results DataGrid
  14. The results DataGrid is bound to the books list in the ModelLocator, and shows the results.