NML
NML is a syntax framework for programming languages.
It provides a new alternative to XML and JSON.
NML is suitable for a broad array of programming applications, unlike XML
and JSON, which are more specialised.
How is it different?
XML tags store data in
attributes as well as a single element of
tag content between start and end tags.
- XML tag content can store both text data and nested tags.
- An XML attribute can only store a single string of data.
- You can have as many XML attributes as you like, but they aren't
particularly useful. If we want to store nested data, we're limited to one tag
content element per tag.
NML uses tags too. But NML tags unify the concepts of attributes and tag content into
fields.
- All fields can contain nested tags.
- An un-named default field fills the role of tag content in XML.
It's worth noting that
any XML code can very easily be converted to NML. But
code that takes full advantage of NML's expressive functionality is rather
difficult to convert to XML.
XML | <button id="test">Submit</button> |
NML | <button id={test} {Submit}> |
NML fields are powerful enough to support multiple data types, as well as ordered lists of data elements, like
JSON.
| Examples |
booleans | true, false |
integers | 42, -6, x6A2F |
floating-point | 6.02, b10110011.0s-6 |
strings | {normal text}, [{literal character data}] |
identifiers | myValue, i, href |
tags | <client name={Smith},{John} birthdate=<date y=1987
m=7 d=4>> |
Syntactical features
Rather than each field being limited to a single value, like an XML
attribute, you can supply an ordered list of multiple
field elements,
more like JSON. You can mix different data types within a list. Numbers can be
integers or floating point, and can be input in binary, octal, decimal or hex.
Boolean values are specified using reserved identifiers
true and
false.
List | Field element |
 |
 |
- Note that in NML, there is no syntactical difference between
assigning a single element to a field and having a single-element list.
(An NML parser might simply convert single elements to lists as soon as
multiple elements are presented, for example. Or use lists for all fields
regardless of the number of elements.)
Unlike JSON, text elements can contain nested tags, just like XML, except
not limited to a single content element per tag.
(internally, the text element is broken into a list of string elements and
tag elements, whenever nested tags are encountered):
Text |
 |
- Note that <> has a special meaning in NML, it's
used to explicitly split text into separate field elements.
- NML uses braces { } instead of quotes for encapsulating 'text'
data.
In XML, each tag begins with an identifier that classifies what kind of tag it
is. NML generalises this into a 'type' field, which
can contain a comma-delimited list of field elements in the same way as other fields. Rather
than a tag having a single class identifier, it might be qualified by a
namespace as well, or even a string or integer, depending on what's
appropriate for whatever different languages NML is applied to.
Tag |
 |
- Each field other than the type field and the default field is introduced
by an identifier followed by an = sign, like attributes in XML.
But what does the code look like?
For more information, and to see code examples,
download the NML spec in PDF format here.