XML alternative formats

Table of Contents

Rebol-like

This alternative syntax reminds Rebol language. When attributes are missing, use "_". The symbols [, ] are chosen because typing of them does not require Shift pressing. If an attribute value contains spaces, use quotes.

         not XML                          XML

countries _                   |  <countries>
[                             |    <country name="USA">
  country [name=USA]          |       <city name="New York">
  [                           |         ...
    city [name="New York"] [  |       </city>
      ...                     |       <city name="Dalas">
    ]                         |         ...
    city [name=Dalas] [       |       </city>
      ...                     |    </country>
    ]                         |  </countries>
  ]                           |
]                             |

By the way, this format also is simple for parsing and it's very extendible!

PROS: EASY CAN BE USED AS A LANGUAGE FOR DATA AND FOR LOGIC. MORE LOGIC ORIENTED

.Reg-files like

This alternative syntax reminds classic Java properties file. Or Windows .reg files. Long lines continuations start not from the beginning of the line: their first symbols are used as the marker of the beginning, so you can start them with " > " for example, as well. Attributes start with "@".

As a delimiter, "." can be used. Also "/". Or even ":".

PROS: PERFECT FOR PARSING WITH SIMPLE TOOLS - SHELL, GREP, AWK. MORE DATA ORIENTED. PROBABLY ALLOWS VERY HIGH PARSING SPEED. ALSO - VERY AI FRIENDLY

             not XML                                  XML
                                             
countries.0.country.@name: USA             | <countries>
countries.0.country.0.city.@name: New York |   <country name="USA">
countries.0.country.0.city: ...            |     <city name="New York">
 ...                                       |       ...
countries.0.country.1.city.@name: Dalas    |     </city>
countries.0.country.1.city: ...            |     <city name="Dalas">
  ...                                      |       ...
                                           |     </city>
                                           |   </country>
                                           | </countries>

Query without XQuery

It is AI friendly as well, the next data was got with the prompt:

A list of 5 countries with their capitals and the population of capitals in this format:

countries.0.country.@name: USA
countries.0.country.0.city.@name: New York 
countries.0.country.0.city.@population: 123456789

countries.0.country.1.city.@name: Dalas

etc, the same

Let's turn the data to little bit more close to .CSV format (we use the same delimiter between path parts and as the assign symbol):

countries:0:country:@name:USA
countries:0:country:0:city:@name:New York
countries:0:country:0:city:@population:8580000

countries:1:country:@name:France
countries:1:country:0:city:@name:Paris
countries:1:country:0:city:@population:2047602

countries:2:country:@name:Japan
countries:2:country:0:city:@name:Tokyo
countries:2:country:0:city:@population:14260000

countries:3:country:@name:Brazil
countries:3:country:0:city:@name:Brasilia
countries:3:country:0:city:@population:2817381

countries:4:country:@name:Australia
countries:4:country:0:city:@name:Canberra
countries:4:country:0:city:@population:473860

You can run this AWK script on Linux, Windows, Mac, just pass it input data to its stdin:

  BEGIN { FS=":"; criteria=3000000 }
  /:country:@name:/ { country = $5 }
  /:city:@name:/ { city = $7 }
  /:city:@population:/ { if ($7 < criteria) { tot0+=1; tot1+=$7; printf("%s|%s|%d\n", country, city, $7) }}
  END { printf("|total(%d): %d", tot0, tot1) }
France Paris 2047602
Brazil Brasilia 2817381
Australia Canberra 473860
  total(3): 5338843

XQuery is perfect, but you need:

  1. To know it
  2. To have installed tools
  3. It's slower

ROFF-like

It reminds the old documentation system Roff. Or even Python pickle/shelve. The idea is simple: every single dot something is an instruction for a small FSM. For example, .e <something> says to FSM to create an element (tag) <something>. And .ee - to close/complete/pop it. I.e., the format is a stream of instructions.

The instruction .ee can optionally have tag name - in general the rule is: parse as many arguments of an instruction, as you can recognize, any extending comes to the end of arguments. Also all array-like data could have size argument in its opening instruction (like .e countries 5)

       not XML                XML
                                          
.e countries      |  <countries>
.e country        |    <country name="USA">
.a name USA       |      <city name="New York">
.e city           |        ...
.a name New York  |      </city>
....              |      <city name="Dalas">
.ee               |        ...
.e city           |      </city>
.a name Dalas     |    </country>
....              |  </countries>
.ee               |
.ee               |
.ee               |

PROS: PERFECT FOR SIMPLE FSM-BASED PARSERS. DOCUMENTATION ORIENTED. PROBABLY ALLOWS VERY HIGH PARSING SPEED AND WITH SIZE-ARGUMENTS GIVES THE LOWEST MEMORY FRAGMENTATION

Markdown-like

Very human-readable format, reminds Markdown, Org-files and... Yaml. Lists (starts with "-") are for attributes only. Nesting leads to deeper section level (more stars "*").

     not XML                   XML
                                            
# Countries       |  <countries>
## Country        |    <country name="USA">
- name: USA       |      <city name="New York">
### City          |        ...
- name: New York  |      </city>
...               |      <city name="Dalas">
### City          |        ...
- name: Dalas     |      </city>
...               |    </country>
                  |  </countries>

All other XML elements like instructions, entities can be very easy added too. Only a conceptual idea is shown here.

PROS: HUMAN-READABLE AND ALSO DOCUMENTATION ORIENTED