Cookbook: Difference between revisions

Jump to navigation Jump to search
31 bytes added ,  12 March 2014
Line 123: Line 123:
Reading XML in octave can be achieved using the java library [http://xerces.apache.org/ Xerces] (from apache).  
Reading XML in octave can be achieved using the java library [http://xerces.apache.org/ Xerces] (from apache).  


It seems that the matlab's xmlread is just a thin wrapper around the Xerces library which is also included in matlab. One should note however, that Java functions have the working directory set to the working directory when octave starts and the working directory is not modified by a cd in octave. Matlab has the same behavior, as java does not provide a way to change the current working directory (http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4045688). To avoid any issues, it is thus better to use the absolute path to the xml file.
It seems that the matlab's xmlread is just a thin wrapper around the Xerces library. One should note however, that Java functions have the working directory set to the working directory when octave starts and the working directory is not modified by a cd in octave. Matlab has the same behavior, as Java does not provide a way to change the current working directory (http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4045688). To avoid any issues, it is thus better to use the absolute path to the XML file.


You need the jar file xercesImpl.jar and xml-apis.jar from e.g. https://www.apache.org/dist/xerces/j/Xerces-J-bin.2.11.0.tar.gz (check for the latest version)
You need the jar files xercesImpl.jar and xml-apis.jar from e.g. https://www.apache.org/dist/xerces/j/Xerces-J-bin.2.11.0.tar.gz (check for the latest version).
Use javaaddpath to include these files:
Use javaaddpath to include these files:


{{Code|Load comma separated values files|<syntaxhighlight lang="octave" style="font-size:13px">
{{Code|Define java path|<syntaxhighlight lang="octave" style="font-size:1.1em">
   javaaddpath('/path/to/xerces-2_11_0/xercesImpl.jar');
   javaaddpath('/path/to/xerces-2_11_0/xercesImpl.jar');
   javaaddpath('/path/to/xerces-2_11_0/xml-apis.jar');
   javaaddpath('/path/to/xerces-2_11_0/xml-apis.jar');
Line 135: Line 135:
A sample script:
A sample script:


{{Code|Load comma separated values files|<syntaxhighlight lang="octave" style="font-size:13px">
{{Code|Load XML file|<syntaxhighlight lang="octave" style="font-size:1.1em">
  filename = 'sample.xml';
  filename = 'sample.xml';
   
   
Line 153: Line 153:
The file <tt>sample.xml</tt>:
The file <tt>sample.xml</tt>:


{{Code|Sample XML file|<syntaxhighlight lang="xml" style="font-size:1.1em">
  <root>
  <root>
  <data att="1">hello</data>
  <data att="1">hello</data>
  </root>
  </root>
</syntaxhighlight>}}


===Using variable strings in commands===
===Using variable strings in commands===
4

edits

Navigation menu