[R-SIG-Mac] Omegahat's Package XML -- validating with a DTD can freeze R.app
J ö rg Beyer
Beyerj at students.uni-marburg.de
Mon Sep 4 14:43:01 CEST 2006
Hello.
No question, no problem; I just like to inform you about the following
issue. It affects R.app, but not R from the terminal (see specs below for
details about my environment).
I managed to freeze R.app. Several times. But I could track down the
specific circumstances in this special case, and here is what happened.
I have an XML-file with an internal DTD.
During the development I made some changes to the XML data part as well as
to the DTD, and reading and validating it with the XML package and R.app
*worked well* (means: errors were detected and displayed as one would
expect) -- please keep that in mind!
Then I made a certain change, produced a validity problem without noticing
it, saved the XML file without validating it again, and the next day all
went wrong right from the start.
In detail, I made the following (see the XML snippets below): I defined an
empty DTD element "normKey", with two attributes, "key" and "val". While
developing an appropriate S4-'container', I decided that the "val"-attribute
would be better named "value". I changed all XML data elements of my file
accordingly -- but forgot to change the attribute name in the DTD, too,
which remained "val".
My next attempt(s) to parse the file with validation turned on (2 versions
of the critical syntax below) ended with immediately freezing R.app
(Activity Monitor said, R.app didn't answer any more, and I had to force
quit it).
After tracking down the problem and setting the attribute name "val" in the
DTD to "value", everything was back to normal. Testing the same scenario
with R in the terminal DID NOT freeze R (or the terminal), but resulted in
"50 or more warnings" because of the DTD-violation -- that's the expected
and correct behavior of a validator.
## XML-file (** excerpt **)
## DTD-part (internal DTD, by the way)
<!ELEMENT normKey EMPTY>
<!ATTLIST normKey key ID #REQUIRED
val IDREF #REQUIRED>
## XML data-part
<normKey key="iqa" value="IQ.Adult" />
## R-code for parsing (v1)
xmlfile <- "/My/Not/So/Clever/Datafile.xml";
objectAsXML <- xmlRoot( xmlTreeParse( xmlfile, validate=TRUE ));
## R-code for parsing (v2)
xmlfile <- "/My/Not/So/Clever/Datafile.xml";
objectAsXML <- xmlTreeParse( xmlfile, validate=TRUE );
I don't have the time to try to track down the underlying problem -- I have
a workaround, and I have been warned, that's enough for the moment.
If you're concerned, you should check if this issue can be reproduced with
newer builds of R and R.app. Depending on what your results are, it may be
best either to do all XML validation outside R.app, or to validate your
XML's in R.app only with the necessary precautions.
Other than that, the XML package is highly recommended -- fantastic tool.
Best
Joerg
Environment:
------------
Mac OS X 10.4.6
R 2.2.1 ... via R.app *or* the terminal
(BTW, for me R 2.3.1 is a no-op at the moment)
Package XML 0.99-8, compiled with gcc_3.3
More information about the R-SIG-Mac
mailing list