SSAX-SXML 和数字
我使用 SSAX-SXML 来处理仅模仿 XML 数据编码的树结构。所以我想到直接使用 SXML 表示作为要使用的数据结构。一切都运行得很好,我获得了默认访问器和 XPath 的所有功能,我发现它们非常有用。
但我有一个问题。 XML 将所有内容表示为字符串,因此我始终需要从字符串转换为数字,反之亦然。这会降低性能并且只是一个糟糕的设计理念。我正在考虑获取 SXML 列表并将所有字符串一次性转换为数字。但是,有没有一种方法可以让 SXML 直接执行此操作,或者有什么方法可以通过 XML 告诉某些内容应该表示为数字,而不是字符串?
这是我的 SXML 列表:
((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"))))
来自如下所示的 XML(摘录):
<wall uid="2387058723">
<pt x="1.0" y="2.0"/>
<pt x="3.0" y="4.0"/>
</wall>
谢谢。
I'm using SSAX-SXML for working with a tree structure that just mimics the XML data encoding. So I thought of using the SXML representation directly as the data structure to work with. Everything works very well, and I get all the functionality of default accessors and XPath, which I found very useful.
But I have a problem. XML represents everything as strings, so I need to convert from string to numbers and viceversa, all the time. That will kill performance and just a bad design idea. I was thinking of taking the SXML list and transform all strings to numbers in one pass. But, is there a way that SXML directly does that or any way to tell 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 a XML that looks like this (extract):
<wall uid="2387058723">
<pt x="1.0" y="2.0"/>
<pt x="3.0" y="4.0"/>
</wall>
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SSAX 不支持进行类型转换,因为您正确地注意到 XML 缺少任何语义信息。你所能做的就是对你的属性施加一些方案约束。但 SSAX 不支持 XSD。所以它不会有任何用处。
但是将所有字符串转换为数字非常简单,因为解析的 XML 存储在列表中,而处理列表是Scheme 中最自然的事情。 ;-)
但是你会丢失你的 uid 上的前导零。它们可能很重要。
SSAX does not have any support to do type conversion, because as you correctly noticed XML lacks any semantic information. All you can do is putting some scheme constrains on your attributes. But SSAX has no support for XSD. So it would not be of any use.
But converting all strings to numbers is quite simple, because the parsed XML is stored in lists and dealing with lists is the most natural thing in Scheme. ;-)
But you will loose the leading zeros on your uids. They might be significant.