SSAX-SXML and Numbers

I use SSAX-SXML to work with a tree structure that simply mimics the encoding of XML data. So I decided to use the SXML view directly as a data structure for the job. Everything works very well, and I get all the functionality of the default accessories and XPath, which I found very useful.

But I have a problem. XML represents everything as strings, so I need to constantly convert from string to numbers and vice versa. It will kill productivity and just a bad design idea. I was thinking of taking an SXML list and converting all the strings to numbers in one pass. But is there a way that SXML directly or in some way communicates via XML that something should be represented as a number, not a string?

This is my SXML list:

((wall (@ (uid "2387058723")) (pt (@ (y "2.0") (x "1.0"))) (pt (@ (y "4.0") (x "3.0")))) (wall (@ (uid "5493820876")) (pt (@ (y "0.0") (x "0.0"))) (pt (@ (y "100.0") (x "0.0"))) (window (@ (to "0.4") (from "0.2"))) (window (@ (size "1.0") (from "0.2"))) (door (@ (size "1.0") (from "0.2")))) (pilar (@ (uid "692034802")) (center (@ (y "5.0") (x "5.0"))) (dim (@ (b "0.45") (a "0.3")))) (room (@ (label "salon")) (wall (@ (uid "2387058723"))) (wall (@ (uid "5493820876"))) (wall (@ (uid "5394501263"))) (wall (@ (uid "0034923049")))) (entry (@ (doorNumber "0")) (wall (@ (uid "5493820876")))) (num "0,9") (pipe (@ (y "8.0") (x "10.0")))) 

From an XML that looks like this (extract):

  <wall uid="2387058723"> <pt x="1.0" y="2.0"/> <pt x="3.0" y="4.0"/> </wall> 

Thanks.

+6
xml scheme
source share
1 answer

SSAX does not support type conversion, because since you correctly noticed that XML does not contain any semantic information. All you can do is set some schema restrictions on your attributes. But SSAX does not support XSD. So that would be useless.

But converting all strings to numbers is quite simple, because the parsed XML is stored in lists, and the consideration of lists is the most natural in the Schema .; -)

 (define example '((wall (@ (uid "1")) (pt (@ (x "1.0") (y "2.0"))) (pt (@ (x "3.0") (y "4.0")))))) (define (ssax:string->number ssax) (if (string? ssax) (string->number ssax) (if (list? ssax) (map ssax:string->number ssax) ssax))) (ssax:string->number example) 

But you will lose leading zeros on your uids. They can be significant.

+3
source share

All Articles