Comments on: software to graph/analyse numeric data in xml file?
http://ask.metafilter.com/115755/software-to-graphanalyse-numeric-data-in-xml-file/
Comments on Ask MetaFilter post software to graph/analyse numeric data in xml file?Tue, 03 Mar 2009 21:12:55 -0800Tue, 03 Mar 2009 21:12:55 -0800en-ushttp://blogs.law.harvard.edu/tech/rss60Question: software to graph/analyse numeric data in xml file?
http://ask.metafilter.com/115755/software-to-graphanalyse-numeric-data-in-xml-file
software to graph/analyse numeric data in xml file?<br>
I've got lots and lots of numbers and I'd like to look at a pretty graph. <br /><br /> Hello,<br>
<br>
I have some data in an xml files that I want to plot and analyse.<br>
<br>
The data consists of sample points, each sample has a value and a timestamp. The samples are all sorted by time, so I think it should be fairly straight forward to plot the points<br>
<br>
I might end having to look at lots of similar files, so it would be good to find a really efficient way of processing the data.<br>
<br>
Mostly I'll just need to look at the graph, occasionally I'll want to super impose two graphs on top of each other.<br>
<br>
I have used Mathematica, so thats somewhat familiar ground, but I wouldn't have a clue how to import data into it<br>
<br>
any suggestions?<br>
<br>
cheers<br>
<br>
Mat<br>
<br>
here's a snippet of the xml:<br>
<br>
the first number is the value<br>
the second is the timestamp<br>
<br>
<br>
<code><br>
<array><br><br>
<real>-0.47238370776176453</real><br><br>
<real>2616.4930366660001</real><br><br>
</array><br><br>
<array><br><br>
<real>-0.45421510934829712</real><br><br>
<real>2616.502291666</real><br><br>
</array><br><br>
<array><br><br>
<real>-0.43604651093482971</real><br><br>
<real>2616.512025</real><br><br>
</array><br><br>
</code>post:ask.metafilter.com,2009:site.115755Tue, 03 Mar 2009 20:51:58 -0800compound eyedataxmlBy: eli_d
http://ask.metafilter.com/115755/software-to-graphanalyse-numeric-data-in-xml-file#1660615
microsoft excel would probably handle the data well... it has pretty straightforward import wizards and chart creation wizards. someone else will have to chime in with more detail on that, mathematica, or something else though...comment:ask.metafilter.com,2009:site.115755-1660615Tue, 03 Mar 2009 21:12:55 -0800eli_dBy: eli_d
http://ask.metafilter.com/115755/software-to-graphanalyse-numeric-data-in-xml-file#1660616
or the openoffice.org spreadsheet program... (free and open source)comment:ask.metafilter.com,2009:site.115755-1660616Tue, 03 Mar 2009 21:13:47 -0800eli_dBy: nat
http://ask.metafilter.com/115755/software-to-graphanalyse-numeric-data-in-xml-file#1660627
<a href="http://reference.wolfram.com/mathematica/XML/tutorial/ImportingXML.html">Documentation</a> from Mathematica is often quite useful.<br>
<br>
(Although I think I'd want to use Matlab for such a graph. Don't have a good reason for that.)comment:ask.metafilter.com,2009:site.115755-1660627Tue, 03 Mar 2009 21:25:42 -0800natBy: hAndrew
http://ask.metafilter.com/115755/software-to-graphanalyse-numeric-data-in-xml-file#1660807
Here's how you can do it in a couple of lines of Mathematica code. I enclosed your snippet in <xml></xml> and saved it in "test.xml".<br>
<br>
To import the XML file, type<br>
<br>
z = Import["test.xml"]<br>
<br>
You'll see that z comprises XMLElement objects and so on. The way to proceed is to specify some simple Mathematica pattern-matching transformation rules to interpret these.<br>
<br>
Here are some suitable rules. I strip away everything except "array" and "real" tags. I treat "array" as a List. I parse "real" as a mathematical expression (in this case, a number):<br>
<br>
rules = {<br>
XMLElement["array", _, list_] :> list,<br>
XMLElement["real", _, {digits_}] :> ToExpression[digits],<br>
XMLElement["xml", _, content_] :> content,<br>
XMLObject["Document"][_, content_, _] :> content<br>
}<br>
<br>
Now z //. rules gives your parsed data. For example, try<br>
<br>
ListLinePlot[z //. rules]<br>
<br>
I hope this helps.comment:ask.metafilter.com,2009:site.115755-1660807Wed, 04 Mar 2009 01:59:20 -0800hAndrewBy: compound eye
http://ask.metafilter.com/115755/software-to-graphanalyse-numeric-data-in-xml-file#1660843
Thanks very much for the help and suggestions,<br>
<br>
Nat thanks I'm looking through the mathematica documentation.<br>
<br>
hAndrew thank you for the code.<br>
<br>
While I haven't been able to get it to work, you've started me off in the right direction.<br>
it imports just fine, but I can't get it to extract anything from the xml<br>
<br>
But now that I know there's something called pattern matching, I've found the guide/RulesAndPatterns section of the documentation, so I guess I'll work from there<br>
<br>
cheers <br>
mathewcomment:ask.metafilter.com,2009:site.115755-1660843Wed, 04 Mar 2009 04:00:14 -0800compound eyeBy: hAndrew
http://ask.metafilter.com/115755/software-to-graphanalyse-numeric-data-in-xml-file#1661399
I am happy to help if you find yourself stuck. Just send me a MeFi mail. Another good place to ask Mathematica questions (and find out if similar questions have been asked before) is <a href="http://groups.google.com/group/comp.soft-sys.math.mathematica/topics?pli=1">mathgroup</a>.comment:ask.metafilter.com,2009:site.115755-1661399Wed, 04 Mar 2009 11:44:42 -0800hAndrewBy: compound eye
http://ask.metafilter.com/115755/software-to-graphanalyse-numeric-data-in-xml-file#1662324
Thanks hAndrew,<br>
<br>
While the intention of your code made sense to me, i just couldn't make it filter anything, and not really understanding the syntax, I found the documentation a little terse.<br>
<br>
<br>
In the course of trying to figure out the mathematica language syntax, I stumbled across sage, which is open source and uses python as the scripting language.<br>
<br>
and was able to make a plot using:<br>
<pre><br>
<code><br>
from xml.dom import minidom <br>
doc = minidom.parseString(data) <br>
L = [] <br>
for a in doc.firstChild.childNodes: <br>
if a.nodeName == 'array': <br>
x = float(a.childNodes[3].firstChild.data) <br>
y = float(a.childNodes[1].firstChild.data)<br>
L.append((x,y)) <br>
list_plot(L) <br>
</code><br>
</pre><br>
<br>
cheers matcomment:ask.metafilter.com,2009:site.115755-1662324Thu, 05 Mar 2009 00:05:03 -0800compound eye