[Python-3000] XML literals

Antoine Pitrou solipsis at pitrou.net
Sat Apr 22 17:42:11 CEST 2006


Le samedi 22 avril 2006 à 16:17 +0100, Guido van Rossum a écrit :
> Groovy has a different approach that doesn't blend the two syntaxes,
> but rather gives you more native syntax for constructing DOM trees (or
> event streams; it wasn't clear from the description I saw today). That
> makes perhaps more sense; it avoids the lexical ambiguities and a
> parentheses-based syntax is easier to type than XML. Maybe this
> example (which I am making up) suffices:
> 
> frag1 = element["some content"]
> 
> frag2 = element["some content",
>                              child(attribute='value')["spam & egg"]]

You might want to take a look at CDuce.
It is a functional language dedicated to transformation of XML
documents. It has a powerful typing system (including structural pattern
matching), and also features a clever syntax for representing XML
fragments in-code.

Here is a simplified example from the tutorial :

let parents : ParentBook =
<parentbook>[
  <person gender="F">[
    <name>"Clara"
    <children>[
      <person gender="M">[
        <name>"Pål André"
        <children>[]
      ]
    ]
    <email>"clara at lri.fr"
    <tel>"314-1592654"
  ] 
  <person gender="M">[
    <name>"Bob"
    <tel kind="work">"271828"
    <tel kind="home">"66260"
  ] 
] 

http://www.cduce.org/tutorial.html

Regards

Antoine.




More information about the Python-3000 mailing list