This is a C# implementation of a parser that conforms to the Hal specification
Hal is a simple hypermedia format that has both a XML and JSON variant. This parser currently only supports the XML variant. Hal is an easy way to return representations of resources that have links and other embedded resources. Application semantics are defined through the use of known link relations.

The Hal.Net nuget can be found here

Hal documents can be created like this:

           var hal = new HalDocument("");
            hal.AddNamespace("td", new Uri(""));

            hal.AddLink("td:search", "/todo-list/search;{searchterm}");
            hal.AddLink("td:description", "/todo-list/description");
            hal.AddProperty("created_at", "2010-01-16");
            hal.AddProperty("updated_at", "2010-02-21");
            hal.AddProperty("summary", "An example list");

            hal.CreateResource("td:owner", "")
                    .AddLink("td:friend", "")

            hal.CreateResource("td:item", "")
                .AddProperty("title", "Find Mug")
                .AddProperty("details", "Find my mug.")

                .AddTypedResource("td:attachment", "text/plain", @"
                PLACES MY MUG COULD BE
              - Garden
              - Roof
              - Zipcar
              - Shelf
                .AddLink("td:next", "")

            hal.CreateResource("td:item", "")
                .AddProperty("title", "Make tea")
                .AddProperty("details", "Mike nice tea that is green. (Gyokuro)")
                .AddLink("td:prev", "")

This parser also provides a simple path syntax to allow access to individual components of the Hal document

    XElement propertyElement1 = hal.FindProperty("/summary").Value;    

    XElement propertyElement2 = hal.FindProperty("/td:owner/name").Value;
    XElement propertyElement3 = hal.FindProperty("/td:item[2]/title").Value;

Last edited Aug 9, 2011 at 4:40 AM by DarrelMiller, version 5