stepthom / math-fun

Just testing out some fun with mathematics.
2 stars 2 forks source link

Create XML output #14

Closed stepthom closed 11 years ago

stepthom commented 11 years ago

Currently, the output for each function, sent to stdout, looks like this:

Function 7:
f(x) = -27/17x^50/2 - 11/26x^77/49 + 12/47x^62/62 - 7/48x^58/93 
Differential Function 7:
f(x) = -1350/34x^48/50 - 847/1274x^28/77 + 744/2914x^0/62 - 406/4464x^-35/58 

Change it to be in XML format:

<function>
  <output>
    f(x) = -27/17x^50/2 - 11/26x^77/49 + 12/47x^62/62 - 7/48x^58/93 
  </output>
  <derivative>
    f(x) = -1350/34x^48/50 - 847/1274x^28/77 + 744/2914x^0/62 - 406/4464x^-35/58 
  </derivative>
</function>

The set of all generated functions should be wrapped in the root node <functions>.

The output should still go to stdout.

ctcaldwell commented 11 years ago

Steve, can you please clarify this task?

Outputting valid XML I understand. Typically though, it is up to the viewing application to "beautify" the XML for display. Your sample output above indicates you're wanting the output to be human readable within the terminal, with tabbing/indentation, etc. Is that correct?

stepthom commented 11 years ago

@ctcaldwell Let's not worry too much about pretty printing. Note that, for now, we are only outputting regular text to stdout that happens to comply with the XML format; we are not creating an XML DOM object in memory, building it up using the DOM API, and then calling something like tree.print(). So the spacing and formatting is totally up to us. You will probably have a line somewhere that says System.out.println(" <deriviative>");, with explicit spaces in there. Since our tree is so simple, this is easier than using XML DOM.

The intent is that the XML output will be easier to read, and if someone wants to save the output to a file, they can just redirect the output themselves.

Does that help?

ctcaldwell commented 11 years ago

Yes thanks. I had assumed you were wanting this done on the cheap. Just wanted to verify you wanted the formatting enhancements for readability.

ctcaldwell commented 11 years ago

Created pull request.

XML output is specified by the new -x command line parameter.

ctcaldwell commented 11 years ago

XML output fixed to correctly include the element which contains the subelements and .