You’ve run into a small bug with the property list to tree conversion – basically, it isn’t expecting something that’s already a tree as a value in a property list. That will be fixed in the next version of Eggplant.
Meanwhile, you can simply leave off the nested call to the tree() function:
put tree(foo: (bar:1) )
While converting a property list to a tree, nested property lists will be converted too, so that should give you what you want. (Note: quotes aren’t needed around property names unless they contain special characters.)
Should probably output “<></>” (same as “an empty tree”)
Instead, outputs “()”[/quote]
Yes, that’s a good point. Thanks for pointing that out. It’s treating the empty list as text, but converting any list to a tree should really treat it as a sequence of nodes within an unnamed element, as you suggest. This will be fixed for a future release.
set foo to "<html><body>hello</body></html>"
put foo
put tree(foo)
put tree(string:foo)
In “put tree(string:foo)”, it appears to be trying to parse foo as a tree.[/quote]
This isn’t really a bug. The conversion from a property list to a tree operates in a “deep” fashion, doing its best to interpret each value as a possible subtree. So if a value is proper XML it is converted to a subtree at that point.
I can see how that isn’t what you really want in this case, since you just want the html text stored in the tree. For now, you’ve already found one possible way to prevent this. Here’s another way to explicitly specify that you want a text node at some point in a tree, using the special “_text” property:
set html to "<html><body>hello</body></html>"
set xml to tree(value:(_text:html))
put xml
Hopefully one of these approaches will work well for your needs.