Monday, May 05, 2008
If your project is leveraging a Web service and you need more data to start out with, here is what you can do:

1) Write code in your device application that calls the addX (X is your thing ... restaurant, task, etc.) of your Web service. Make sure you provide unique IDs!

2) Create a network location (see previous blog) and work directly in the XML. Open your XML file in Visual Studio. Can be a quick way, but also error prone, which may lead to problems in the deserialization of your XML data. Use copy/paste as much as possible.

3) Modify the generateData method in your Web service. Right now it only creates one test item. Simply repeat as much as you like the code that creates the data item, assigns the values, and adds it to the array list. Make sure you provide unique IDs!
        Dim al As New ArrayList()
        Dim da As DataItem()
        Dim di As DataItem

        Try
            'test item (your item may have other attributes!)
            di = New DataItem
            di.ID = "0000" 'provide unique ids
            di.Name = "test"
            di.Value = 1.0
            al.Add(di)

            'another item
            di = New DataItem
            di.ID = "0001"
            di.Name = "test again"
            di.Value = 1.0
            al.Add(di)

            '... and so on

            da = al.ToArray(GetType(DataItem))

            Return DataManagementSystem.saveDataItems(da)
        Catch ex As Exception
            Return ex.Message
        End Try



I would use 3 to get started (and reset if necessary) and then work using 2.

MH

5/5/2008 12:07:06 PM (Central Standard Time, UTC-06:00)
 Friday, April 04, 2008

How can one leverage XML without knowing much about XML?

The answer, as indicated in the previous posting, is XML serialization.

An XML serializer can be used to turn the data stored in objects into XML (and back from XML into objects). All the serializer needs to know is the class the objects are derived from. The serializer looks at the class definition and creates a corresponding XML structure. (The class has to be "serializable" and there are some cases where this automatic process will not work!)

Below is some example code in which an XML serializer is leveraged to save and load DataItem objects. The loadDataItems function reads the XML from a file and returns an array of DataItem objects. (DataItem could be replaced with Person, Patient, Contract, Restaurant, ... whatever your class is!). The saveDataItems function takes an array of DataItem objects and writes it to an XML file.


MH

--- Code ---

'need these imports at the top of your VB code!
Imports System.Xml
Imports System.Xml.Serialization
Imports System.IO

...

Public Shared Function loadDataItems() As DataItem()
Dim mySerializer As XmlSerializer
Dim dataItems As DataItem()

Try
mySerializer = New XmlSerializer(GetType(DataItem()))

' To read the file, create a FileStream.
Dim myFileStream As FileStream = _
New FileStream(_filePath, FileMode.Open)

' Call the Deserialize method and cast to the object type.
dataItems = CType(mySerializer.Deserialize(myFileStream), DataItem())
Return dataItems
Catch ex As Exception
Return Nothing
End Try

End Function

Public Shared Function saveDataItems(ByVal dataItems As DataItem()) As Boolean
Dim mySerializer As XmlSerializer

Try
mySerializer = New XmlSerializer(GetType(DataItem()))

' To write to a file, create a StreamWriter object.
Dim myWriter As StreamWriter = _
New StreamWriter(_filePath)

mySerializer.Serialize(myWriter, dataItems)
myWriter.Close()
Return True
Catch ex As Exception
Return False
End Try

End Function

project | XML
4/4/2008 9:22:02 AM (Central Standard Time, UTC-06:00)
 Thursday, April 03, 2008

I had a chance today to review the project requirements documents and plans.

There are some very interesting projects, some even with potential for becoming something more than just a class project.

I encourage everyone to share their ideas, designs, and other insights related to the project on the blog. (Tag these entries with the keyword "project" so others can search for it!) It may give others some good ideas, but can also help to shape your own thinking.

Here are some of the key things that most need to focus on right now:

  • Understand the data: identify the key entities, their characteristics, and relationships
  • Define the actions: identify and describe the actions that uses may take, in "business" not in technical terms ("the user updates the database" is too technical, "updates the task status to completed" is more appropriate).

The conceptual data design will enventually result in a set of classes for your application. The great thing is that having these classes it is quite easy to save data stored in objects of this class in XML files ... without knowing much about XML. The process is called serialization and .NET provides a XmlSerializer class that makes this process quite simple.

More later ...

MH

 

 

 

4/3/2008 10:18:46 PM (Central Standard Time, UTC-06:00)
Search
Navigation
On this page....
Archives
<September 2008>
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
Aggregate Me!
RSS 2.0 | Atom 1.0 | CDF
Categories
Blogroll
Contact me
Send mail to the author(s) E-mail
Themes
Administration