DrScheme and XML

2 views
Skip to first unread message

Christopher Browne

unread,
Nov 26, 1999, 3:00:00 AM11/26/99
to
I just got the announce about the DrScheme ODBC support,
<http://www.cs.rice.edu/CS/PLT/packages/srpersist/>; rather
encouraging, to be sure...

The other neat thing that is offered lately is the ability to 'grope'
XML documents.

> (load "collects/xml/xml.ss")
(define p (open-input-file "/home/cbbrowne/html/xmlsample.xml"))
(define doc (read-xml p))
(close-input-port p)
> doc
#<struct:document>
> (define x (xml->xexpr doc))
> x
#<struct:document>

Up to this point everything is fine. Unfortunately, all I'm getting
now from any of the xexpr-related operators is:
#<struct:document>

I can display stuff as XML, on the XML side of things...
> (display-xml (xexpr->xml x))

<dir size="30">
<directoryentry type="dir">
<attribs value="drwxr-xr-x"/>
<owner id="hd1adm"/>
<group id="sapsys"/>
<size value="512"/>
<dates moddate="99/02/04 17:01"/>
<name id="./"/>
</directoryentry>
<directoryentry type="dir">
<attribs value="drwxr-x---"/>
<owner id="hd1adm"/>
<group id="sapsys"/>
<size value="7680"/>
<dates moddate="99/03/01 10:42"/>
<name id="../"/>
</directoryentry>
<directoryentry type="file">
<attribs value="drwxr-xr-x"/>
<owner id="hd1adm"/>
<group id="sapsys"/>
<size value="7680"/>
<dates moddate="99/03/01 10:42"/>
<name id="impdom"/>
</directoryentry>
</dir>
>

I'm not sure where to go from here, on how to "walk the xexpr tree."

Any demos/pointers?
--
"...and scantily clad females, of course. Who cares if it's below
zero outside" -- Linus Torvalds
cbbr...@hex.net- <http://www.ntlug.org/~cbbrowne/xml.html>

Shriram Krishnamurthi

unread,
Nov 26, 1999, 3:00:00 AM11/26/99
to
cbbr...@news.hex.net (Christopher Browne) writes:

> I just got the announce about the DrScheme ODBC support,
> <http://www.cs.rice.edu/CS/PLT/packages/srpersist/>; rather
> encouraging, to be sure...
>
> The other neat thing that is offered lately is the ability to 'grope'
> XML documents.

> [...]


> Up to this point everything is fine. Unfortunately, all I'm getting
> now from any of the xexpr-related operators is:
> #<struct:document>
>

> I'm not sure where to go from here, on how to "walk the xexpr tree."

Right; sorry. We will eventually write a document about processing
documents with the XML collection. For now, there are two options.

1 -- Preserve XML Structures

If you go into Help | Help Desk and type "xml", you will get the XML
collection's documentation. In there, you will find all the structure
definitions. Thus, for instance, in this source document

----------------------------------------------------------------------
<poem title="The Lovesong of J. Alfred Prufrock"
poet="T. S. Eliot">
<stanza>
<line> Let us go then, you and I, </line>
<line> When the evening is spread out against the sky </line>
<line> Like a patient etherized upon a table: </line>
</stanza>
<stanza>
<line> In the room the women come and go </line>
<line> Talking of Michaelangelo. </line>
</stanza>
</poem>
----------------------------------------------------------------------

I can extract the first line of each stanza with

----------------------------------------------------------------------
(map (lambda (s)
(pcdata-string
(car
(element-content
(car
(element-content s))))))
(element-content
(document-element
(read-xml (open-input-file "lovesong.xml")))))
----------------------------------------------------------------------

(You'll have to study the structure definitions to make sense out of
this code; sorry.)

2 -- Convert to X-Expressions

The x-expression format treats XML content as a stylized form of
s-expressions, so you could also write:

----------------------------------------------------------------------
(map (lambda (stanza)
(cadr (cadr stanza)))
(map xml->xexpr
(element-content
(document-element
(read-xml (open-input-file "lovesong.xml.scm"))))))
----------------------------------------------------------------------

Both programs produce the output

----------------------------------------------------------------------
("Let us go then, you and I, " "In the room the women come and go ")
----------------------------------------------------------------------

I recommend using option 1 for now, because we may be changing some
things in the x-expression representation.

'shriram

[PS: I tried sending you email earlier this week with the paper pointer,
but your address bounced. Please send me email from the address that
I should write to instead.]

Reply all
Reply to author
Forward
0 new messages