SU Ruby + XML
-
I will try to look tomorrow when I get on my Windows machine and make a SU friendly package of a XML parser.
It all depends on what XML files you need to parse - if they are static, then you can write a specific XML parser yourself and save the troubles. I wouldn't use XML for anything, hate that format
-
There are several different uses for XML I'd like to use. I like the format, maybe from working with websites...
-
@unknownuser said:
I will try to look tomorrow when I get on my Windows machine and make a SU friendly package of a XML parser.
It all depends on what XML files you need to parse - if they are static, then you can write a specific XML parser yourself and save the troubles. I wouldn't use XML for anything, hate that format
hmm.. These XMl packages - are they PC only?
The nokogiri package has different packages for different platform. That could be a problem. I was hoping to find a cross platform solution. If REXML is cross platform I don't mind it's not too fast. But what troubles me with that is it's conflict with the Set class.
-
@thomthom said:
These XML packages - are they PC only?
almost everything that needs speed in Ruby is implemented as an extension, so it is platform dependent. some gems are precompiled (e.g. for Windows), others are in source form and compiled on user machine to gather additional speed on optimizations (e.g. Mac)
http://github.com/jnunemaker/happymapper sounds interesting but again, has a lot of requirements
-
Seeing how getting an XML parser working I think I will go for a custom format and make a simple parser that creates nested Hashes. In fact, I have to make my own Hash object as I want to traverse the Hash in the order the items where inserted.
But I'd still like to be able to read XML data from SU ruby. There's some other projects I'd like to use it which involves reading existing XML based files.
-
and? did you manage to get something working that could parse xml?
-
No - I've still not found a good solution.
-
Thomthom, what do you actually want?
If you don't need the full DOM, then these big (often slow) XML parsers may be a hammer to crack a nut.
If you're just looking to use XML as a simple text mark-up of parameters etc, then writing something in Ruby that yanks out tag-value pairs would be trivial.
-
You got a point there. It's mostly simple XML files with tags and attributes.
Could make a simple reader and writer. Make a custom class that holds values and attributes, read the XML file as a nested object.
K.I.S.S. -
I write an xml file in ruby, pass it to my webdialog, and use the browser to parse the xml and generate my html table dynamically.
Works awesome.
-
@unknownuser said:
I write an xml file in ruby, pass it to my webdialog, and use the browser to parse the xml and generate my html table dynamically.
Works awesome.
Todd, you're working too hard. Replace the XML with JSON (no harder, may be easier in Ruby), pass it to your WebDialog and "parse the XML" is just
eval( foo = json )
. Ifjson
is a valid JavaScript object, even a complex one nesting arrays and other objects as properties (that in turn nest other ...), you're done. -
No, I'm working smart. With what I am doing with XML, I can allow user customization of the entire dialog for table layout, ordering, field values, content, etc., and never have to touch how my ruby script generates the data again.
-
So you import the xml file into the webdialog and in there you parse it? With a javascript script or something else?
I'm getting lost here. -
@pout said:
So you import the xml file into the webdialog and in there you parse it? With a javascript script or something else?
I'm getting lost here.I display a webdialog. In the webdialog, on some user action, (a javascript event), a javascript function calls a Ruby callback, which iterates over the SketchUp model and builds an XML document of it. Then, the callback finished by setting a javascript variable with the xml document. Then, back in javascript, I call the browser to parse the XML document. I then (in javascript) iterate over the parsed document to build my dynamic html <table>.
Todd
-
@unknownuser said:
a Ruby callback, which iterates over the SketchUp model and builds an XML document of it
Why is XML better than JSON?
-
It's not that XML is better or JSON is better. Forward thinking, XML is what I chose to use.
XML does, however, interface with the rest of the world better than JSON.
-
@unknownuser said:
@pout said:
So you import the xml file into the webdialog and in there you parse it? With a javascript script or something else?
I'm getting lost here.I display a webdialog. In the webdialog, on some user action, (a javascript event), a javascript function calls a Ruby callback, which iterates over the SketchUp model and builds an XML document of it. Then, the callback finished by setting a javascript variable with the xml document. Then, back in javascript, I call the browser to parse the XML document. I then (in javascript) iterate over the parsed document to build my dynamic html <table>.
Todd
ok, i get this.
But different browsers have different ways to parse XML data.
What kind of code do you use so each browser can handle the xml?
In my case i want to import an xml.
So i parse it with the webbrowser of the webdialog. But due to the several possible browsers (IE 5-6-7, Safari, FF, ...) this is so difficult to manage.
Do you have a cross browser script that reads XML files? -
@pout said:
But due to the several possible browsers (IE 5-6-7, Safari, FF, ...) this is so difficult to manage.
IE and webkit is the only options.
-
Hey ThomThom,
Can you explain a bit more?
Thx -
With Webdialogs you only deal with IE (under Windows) and webkit (under OSX). All other browsers are irrelevant.
Advertisement