Feb MAR JUL
Previous capture 16 Next capture
2011 2012 2013
16 captures
14 Mar 12 - 11 May 15
sparklines
Close Help
      Loading...
Skip to end of metadata
Go to start of metadata

The Simple Declarative Language provides an easy way to describe lists, maps, and trees of typed data in a compact, easy to read representation. The simple and intuitive API allows you to read, write, and access all the datastructures using a single class. For property files, configuration files, logs, and simple serialization requirements, SDL provides a compelling alternative to XML and Properties files. Implementations are available for Java and .NET; a port to C++ is in the works, with more languages on the way.

30 Second Intro

An SDL Tag can be as simple as a name and a value. Tags can also have value lists, attributes, and children.

Simple Example: A tag with a value
size 4
A tag with a value list
sizes 23 35 12 53

# To fetch this list (Java example)
#    List values = root.getChild("sizes").getValues();
A tag with a value list and attributes
ages 26 24 25 dog_years=false date_of_survey=2005/12/05

# To fetch this list (C# example)
#    IList<object> values = root.GetChild("sizes").Values;
# To fetch the attributes call (C# example)
#    IDictionary<string,object> atts = root.GetChild("sizes").Attributes;
A tag with a value list, attributes, and children.
people location="Tokyo" {
    person "Akiko" friendly=true {
        hobbies {
            hobby "hiking" times_per_week=2
            hobby "swimming" times_per_week=1
        }    
    }

    person "Jim" {
        hobbies {
            hobby "karate" times_per_week=5      
        }    
    }
}
The same structure using anonymous tags (which automatically take the name "content")
people location="Tokyo" {
    "Akiko" friendly=true {
        hobbies {
            "hiking" times_per_week=2 skill_level=5
            "swimming" times_per_week=1
        }    
    }

    "Jim" {
        hobbies {
            "karate" times_per_week=5      
        }    
    }
}

If the above example is stored in a file called "/myfiles/people.sdl", the following Java code will fetch Akiko's hobbies.

Tag root = SDL.read(new File("/myfiles/people.sdl"));
List<Tag> hobbies = root.getChild("people").getChild(0).getChild("hobbies").getChildren();

API Tips

The SDL class (SDLUtil in C#) offers a number of useful convenience methods.

// Parse an SDL literal and get the value
Calendar c = (Calendar)SDL.value("1995/12/05 12:30:23.234-PST");

// Parse a list of values
List stuff = SDL.list("23 true 05:23:24 `hello` 34.12bd");

// Parse a map of attributes
Map map = SDL.map("name=`Jose` height=1.8 smoker=false");

The beef of the API is in the Tag and SDL classes. In fact, you can parse, modify and write out SDL code using nothing but the Tag class.

For more details on the APIs and language see the language guide and JavaDocs (the Tag class in particular.)

Recently Updated

 
Navigate space
      Loading...
Labels: