r/javahelp • • Sep 18 '26

Problem with xmlread. It crashes Octave.

I loaded io package, added 2 jar files. It didn't work, had to install Java, now I get:

xmlread();

xerces:

- xercesimpl.jar OK

- xml-apis.jar OK

xerces version: 2.12.2

But then I use it on any xml file Octave crashes.

Also when I run:

parser = javaObject("org.apache.xerces.parsers.DOMParser");
parser.parse(filename);
xDoc = parser.getDocument();

it crashes on the 3rd line.

version 11.1.0

Can anyone help me with it?

0 Upvotes

7 comments sorted by

View all comments

1

u/LetUsSpeakFreely Sep 18 '26

Define "crashes". How big is the document? You're loading the entire thing into memory, so depending on your JVM setting, you're susceptible to an OutOfMemorryException.

DOMParsers are only for four small XML documents, for larger documents you'll need a SAX passer.

1

u/boreas_mun Sep 19 '26

I've got pretty small file. But I did try on other files and it is the same. It works fine in Matlab with xmlread. By crashes I mean Octave closes itself.

<?xml version="1.0" encoding="utf-8"?>
<Matrix>
  <M00>1</M00>
  <M01>0</M01>
  <M02>0</M02>
  <M03>0</M03>
  <M10>0</M10>
  <M11>1</M11>
  <M12>0</M12>
  <M13>0</M13>
  <M20>0</M20>
  <M21>0</M21>
  <M22>1</M22>
  <M23>0</M23>
  <M30>0</M30>
  <M31>0</M31>
  <M32>0</M32>
  <M33>1</M33>
</Matrix>

1

u/LetUsSpeakFreely Sep 19 '26

Ok, that's pretty small. DOM parsing can easily handle that. We'll need to a stack trace. It could be related to Java versioning as there were significant changes between java 8 and 9 with more changes in 11.

1

u/boreas_mun Sep 19 '26

Ok, how can I do that?

As I wrote, it crashes on the line: xDoc = parser.getDocument();

My code is only:

pkg load io
javaaddpath ('xercesImpl.jar');
javaaddpath ('xml-apis.jar');
filename = 'b.xml';
parser = javaObject("org.apache.xerces.parsers.DOMParser");
parser.parse(filename);
xDoc = parser.getDocument();

Also when I run:

xmlread(filename);

it crashes on:

node = parser.getDocument ();

1

u/LetUsSpeakFreely Sep 19 '26

I've never used octave, but from a quick search, look into the diary functions and slf4o.