0
$\begingroup$

I'm having some trouble re-importing the output of an x3d export of a 3D plot, and I'd like to understand why it's failing and how to fix it.

The short version of what I want to do is to make a 3D plot, export it into x3d from within Mathematica, and then re-import it as XML:

plot = Plot3D[x^2 - y^3, {x, 0, 1}, {y, 0, 1}];

Export[FileNameJoin[{NotebookDirectory[], "test.x3d"}], plot]

Import[FileNameJoin[{NotebookDirectory[], "test.x3d"}], "XML"]

The reason I want to do this is that the x3d export puts out several lights as well as a black background and I want to get rid of them programmatically. This worked before (and I documented it in this previous thread), and as of v10.1.0 it used to work without any issues.

However, on both the versions I have installed (11.3 and 12.0), this is completely failing to import, and it gives the following errors:

enter image description here

enter image description here

XML`Parser`XMLGet::prserr: MalformedURLException: The URL used an unsupported 
protocol at Line: 2 Character: 102 in ~/Desktop/test3d/test.x3d.

Import::fmterr: Cannot import data as XML format.

The problem seems to be in the first two lines of the exported x3d file, which read

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE X3D PUBLIC 'ISO//Web3D//DTD X3D 3.0//EN' 'http://www.web3d.org/specifications/x3d-3.0.dtd'>

For some reason, Mathematica seems to think that the URL is "malformed", but I don't know why, or why http is suddenly an "unsupported protocol". The only thing I can think of is to manually change it to https, in which case the error changes to

XML`Parser`XMLGet::prserr: RuntimeException: Could not open DTD file '~/Desktop/test3d/https://www.web3d.org/specifications/x3d-3.0.dtd' at Line: 2 Character: 103 in /home/episanty/Desktop/test3d/test.x3d.

which is a pretty hilarious way to understand URLs. So: what's going on? Is the XML importer broken? (this Community post seems to have similar issues.)

As a workaround, the advice in this answer to turn off the ReadDTD option,

Import[FileNameJoin[{NotebookDirectory[], "test.x3d"}], "XML", "ReadDTD" -> False]

seems to work OK, but that's a bizarre thing to have happen to a file that was literally just exported by Mathematica itself just a second ago. So: what's going on here?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.