Re: XML support in E

Thomas Leonard <tal-v5nx5w6akNyLE8xUarVfuPLx9OUvmyODWmv/[email protected]>
Newsgroups gmane.comp.lang.e.general
Organization IT Innovation
Message-ID <[email protected]>
On Tue, 2010-01-12 at 17:06 -0500, Kevin Reid wrote:
> On Oct 26, 2009, at 13:08, Thomas Leonard wrote:
> 
> > Could someone give some simple examples showing how to read and write
> > XML using E?
[...]

> There is no E-styled XML library built into E; this is certainly  
> something which ought to be addressed.
> 
> Such a library should of course use immutable trees (vs. e.g. DOM  
> which is mutable) and have quasiliteral/pattern support for users.
> 
> E-on-JavaScript's Updoc-to-HTML component is an example of XML  
> manipulation in E: it uses the Java DOM libraries (and, when a real E  
> XML library exists, should be converted to use it).
>    http://wiki.erights.org/wiki/E-on-JavaScript
> 
> 
> There are two different approaches which could be used for an E XML  
> library: one is to use the Term-tree objects, and merely write an  
> xml__quasiParser which allows one to use the XML-in-TermL embedding,  
> as well as facilities for reading/writing XML documents. The other is  
> to have a distinct object type for XML tree nodes; this has the  
> advantage that its methods can be optimized for the needs of XML  
> applications, and its __printOn would show XML rather than TermL.
> 
> Parsing and printing could be handled for starters by using Java's  
> builtin XML facilities; I'm not sure exactly how much could be reused  
> vs. reimplented.
> 
> Questions:
> 
>    * Would you be interested in working on the project of an XML library
>      for E?
> 
>    * If I were to work on it, would you use it and give feedback?

We'd certainly be interested in testing any XML support. I don't think
I'd be able to help with the implementation though: a selling point for
E was compatibility with existing Java libraries, so telling my manager
I need to spend time implementing XML support is unlikely to fly ;-)

My main concern here is about speed. I temporarily used the JSON support
in part of my code, and it noticeably slows the GUI down when used, even
for quite small documents! Here's a little test case, timing how long it
takes to serialise an example document:

# Example document taken from http://jsonml.org/
def testData := ["table", ["class" => "MyTable", "style" => "background-color:yellow"], ["tr", ["td", ["class" => "MyTD", "style" => "border:1px solid black"], "#550758"], ["td", ["class" => "MyTD", "style" => "background-color:red"], "Example text here"]], ["tr", ["td", ["class" => "MyTD", "style" => "border:1px solid black"], "#993101"], ["td", ["class" => "MyTD", "style" => "background-color:green"], "127624015"]], ["tr", ["td", ["class" => "MyTD", "style" => "border:1px solid black"], "#E33D87"], ["td", ["class" => "MyTD", "style" => "background-color:blue"], "\u00a0", ["span", ["style" => "background-color:maroon"], "\u00a9"], "\u00a0"]]]

def jsonSurgeon := <elib:serial.deJSONKit>.makeSurgeon()

def timeIt(op) {
	op()
	for x in 1..3 {
		def start := timer.now()
		for y in 1..5 {
			op()
		}
		def finish := timer.now()
		println(`Took ${finish-start} ms`)
	}
}

println("Using jsonSurgeon...")
timeIt(fn { jsonSurgeon.serialize(testData) } )

println("Using normal printing...")
timeIt(fn { `$testData` } )

On my laptop, the results are:

Using jsonSurgeon...
Took 3533 ms
Took 2600 ms
Took 2323 ms
Using normal printing...
Took 6 ms
Took 5 ms
Took 6 ms

QuasiParser support would be very nice too (for ensuring correct
quoting, as you mentioned in a later email), and we'd certainly need
namespaces.

Thanks,


-- 
Dr Thomas Leonard
IT Innovation Centre
2 Venture Road
Southampton
Hampshire SO16 7NP

Tel: +44 0 23 8076 0834
Fax: +44 0 23 8076 0833
mailto:tal-v5nx5w6akNyLE8xUarVfuPLx9OUvmyODWmv/[email protected]
http://www.it-innovation.soton.ac.uk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.