caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* xml tree -- variant type tree
@ 2006-02-28 15:23 Hendrik Tews
  2006-02-28 15:43 ` [Caml-list] " Michael Wohlwend
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Hendrik Tews @ 2006-02-28 15:23 UTC (permalink / raw)
  To: caml-list

Hi,

I would like to read an XML file into an element of some variant
type, where each constructor corresponds to precisely one type of
xml nodes. Of course I would need to define the variant type
beforehand. But how to proceed then?

The humps give me the impression that the right library to use is
Gerd Stolpmanns pxp. However, this library will produce an object
tree, which I could probably convert into a variant type with
some effort. 

An alternative would be to use XML-Light, which produces string
labelled trees, and to translate these string trees myself.

Is there some better solution?


Background: I would like to manipulate abstract syntax trees of
C++ programs. I couldn't find a C++ parser in Ocaml, therefore I
would like to use Elkhound/Elsa
(http://www.cs.berkeley.edu/~smcpeak/elkhound/), which can output
the abstract syntax tree as xml file. Extending Elsa is not an
option, because for ast manipulations I prefer ocaml pattern
matching over C++ visitors.

Bye,

Hendrik


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] xml tree -- variant type tree
  2006-02-28 15:23 xml tree -- variant type tree Hendrik Tews
@ 2006-02-28 15:43 ` Michael Wohlwend
  2006-02-28 15:52   ` Alain Frisch
  2006-02-28 15:47 ` Richard Jones
  2006-02-28 20:56 ` philip
  2 siblings, 1 reply; 8+ messages in thread
From: Michael Wohlwend @ 2006-02-28 15:43 UTC (permalink / raw)
  To: caml-list; +Cc: Hendrik Tews

On Tuesday 28 February 2006 16:23, Hendrik Tews wrote:
> Hi,
> An alternative would be to use XML-Light, which produces string
> labelled trees, and to translate these string trees myself.

I found that difficult

> Is there some better solution?

I have used expat to parse my xml. To get more managable code I only use expat 
to fill a queue with the tags found: Start(tag,attr list) and End(tag,text). 
Then I make a stream of the function which reads that queue and can use 
ocaml's streamparsers to parse my xml and build my data structures quite 
easy. It's short, fast and easy changeable. The streamparses can watch only 
for the relevant tags to get the desired information and build the result.

Michael


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] xml tree -- variant type tree
  2006-02-28 15:23 xml tree -- variant type tree Hendrik Tews
  2006-02-28 15:43 ` [Caml-list] " Michael Wohlwend
@ 2006-02-28 15:47 ` Richard Jones
  2006-02-28 15:57   ` Michael Wohlwend
  2006-02-28 20:56 ` philip
  2 siblings, 1 reply; 8+ messages in thread
From: Richard Jones @ 2006-02-28 15:47 UTC (permalink / raw)
  To: Hendrik Tews; +Cc: caml-list

On Tue, Feb 28, 2006 at 04:23:39PM +0100, Hendrik Tews wrote:
> I would like to read an XML file into an element of some variant
> type, where each constructor corresponds to precisely one type of
> xml nodes. Of course I would need to define the variant type
> beforehand. But how to proceed then?

CDuce is a possibility.  It is tremendously powerful, and also quite
obscure to go along with it, but I wrote a nice SOAP/WSDL/XSI parser
using it.

IoXML is another: http://pauillac.inria.fr/~ddr/IoXML/index.html

Rich.

-- 
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] xml tree -- variant type tree
  2006-02-28 15:43 ` [Caml-list] " Michael Wohlwend
@ 2006-02-28 15:52   ` Alain Frisch
  0 siblings, 0 replies; 8+ messages in thread
From: Alain Frisch @ 2006-02-28 15:52 UTC (permalink / raw)
  To: caml-list

Michael Wohlwend wrote:
> I have used expat to parse my xml. To get more managable code I only use expat 
> to fill a queue with the tags found: Start(tag,attr list) and End(tag,text). 
> Then I make a stream of the function which reads that queue and can use 
> ocaml's streamparsers to parse my xml and build my data structures quite 
> easy. It's short, fast and easy changeable. The streamparses can watch only 
> for the relevant tags to get the desired information and build the result.

FWIW, this would be even simpler with PXP's pull parsers (you call a 
function to get the next event instead of providing call-backs).

-- Alain


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] xml tree -- variant type tree
  2006-02-28 15:47 ` Richard Jones
@ 2006-02-28 15:57   ` Michael Wohlwend
  2006-02-28 16:24     ` Alain Frisch
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Wohlwend @ 2006-02-28 15:57 UTC (permalink / raw)
  To: caml-list

On Tuesday 28 February 2006 16:47, Richard Jones wrote:
> CDuce is a possibility.  It is tremendously powerful, and also quite
> obscure to go along with it, but I wrote a nice SOAP/WSDL/XSI parser
> using it.

CDuce is a miracle for me. I tried it for hours and never had the feeling I 
unstood how it worked or why some code worked and some other not :-)  At some 
point I thought it would be easier to code in brainf*ck  than in cduce, but 
that might not be right :-)

 Michael


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] xml tree -- variant type tree
  2006-02-28 15:57   ` Michael Wohlwend
@ 2006-02-28 16:24     ` Alain Frisch
  2006-02-28 18:11       ` Michael Wohlwend
  0 siblings, 1 reply; 8+ messages in thread
From: Alain Frisch @ 2006-02-28 16:24 UTC (permalink / raw)
  To: Michael Wohlwend; +Cc: caml-list

Michael Wohlwend wrote:
> CDuce is a miracle for me. I tried it for hours and never had the feeling I 
> unstood how it worked or why some code worked and some other not :-)  At some 
> point I thought it would be easier to code in brainf*ck  than in cduce, but 
> that might not be right :-)

I'm pretty sure that a lot more useful code has been written in 
brainf*ck than in CDuce, so you're probably right.

Have the hours you spent been long enough to look at the resources to 
learn the language (manual, tutorial, demos, other people's code)? They 
might not be perfect, but they certainly were ok for some people. Also,
I would have recommended to subscribe to the CDuce mailing list, since 
questions asked there usually get a quick answer. Anyway, it would be 
helpful if you could post some feedback, be it negative, as long as it 
contains concrete information.


Cheers,

  Alain


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] xml tree -- variant type tree
  2006-02-28 16:24     ` Alain Frisch
@ 2006-02-28 18:11       ` Michael Wohlwend
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Wohlwend @ 2006-02-28 18:11 UTC (permalink / raw)
  To: caml-list

On Tuesday 28 February 2006 17:24, Alain Frisch wrote:
> Michael Wohlwend wrote:
> Have the hours you spent been long enough to look at the resources to
> learn the language (manual, tutorial, demos, other people's code)? 

yes, I read the tutorial and parts of the manual and tried the examples. I 
only tried it the whole day since I found the features very impressive.

> They might not be perfect, but they certainly were ok for some people. 

I'm sure cduce works, it's just I could not get my task done in the time I 
thought it must be possible; I had difficulties with the syntax and the 
construction of the patterns. As the xml processing was only a minimal part I 
wrote the parser myself. 

 Michael


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] xml tree -- variant type tree
  2006-02-28 15:23 xml tree -- variant type tree Hendrik Tews
  2006-02-28 15:43 ` [Caml-list] " Michael Wohlwend
  2006-02-28 15:47 ` Richard Jones
@ 2006-02-28 20:56 ` philip
  2 siblings, 0 replies; 8+ messages in thread
From: philip @ 2006-02-28 20:56 UTC (permalink / raw)
  To: Hendrik Tews; +Cc: caml-list


On 02/28/2006 04:23:39 PM, Hendrik Tews wrote:
> Hi,
> 
> I would like to read an XML file into an element of some variant
> type, where each constructor corresponds to precisely one type of
> xml nodes. Of course I would need to define the variant type
> beforehand. But how to proceed then?
> 
> The humps give me the impression that the right library to use is
> Gerd Stolpmanns pxp. However, this library will produce an object
> tree, which I could probably convert into a variant type with
> some effort.
> 
> An alternative would be to use XML-Light, which produces string
> labelled trees, and to translate these string trees myself.
> 
> Is there some better solution?
> 
> 
> Background: I would like to manipulate abstract syntax trees of
> C++ programs. I couldn't find a C++ parser in Ocaml, therefore I
> would like to use Elkhound/Elsa
> (http://www.cs.berkeley.edu/~smcpeak/elkhound/), which can output
> the abstract syntax tree as xml file. Extending Elsa is not an
> option, because for ast manipulations I prefer ocaml pattern
> matching over C++ visitors.
> 
> Bye,
> 
> Hendrik
> 
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
> 
> 

Hi Hendrik,

i parsed some with tom, it is very efficient:
http://tom.loria.fr/index.php

-Philip

-- 
And remember, "For every complex problem, there is a solution that is  
simple, neat, and wrong."


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-02-28 20:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-28 15:23 xml tree -- variant type tree Hendrik Tews
2006-02-28 15:43 ` [Caml-list] " Michael Wohlwend
2006-02-28 15:52   ` Alain Frisch
2006-02-28 15:47 ` Richard Jones
2006-02-28 15:57   ` Michael Wohlwend
2006-02-28 16:24     ` Alain Frisch
2006-02-28 18:11       ` Michael Wohlwend
2006-02-28 20:56 ` philip

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).