问题描述:

Using the XML package for R, how can I enforce the use of a DTD file? The following is reported to parse ok, although the second child (description) is not defined as an acceptable child by the DTD file, I would expect an error to be thrown of some kind.

test.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE model SYSTEM "test.dtd">

<model>

<name>Test</name>

<description>Some Description</description>

</model>

test.dtd

<!-- __ MAIN ELEMENT __ -->

<!ELEMENT model(name) >

<!ELEMENT name (#PCDATA) >

script.R

library(XML)

doc = xmlParse("test.xml")

xmlToList(doc)

Output

doc = xmlParse("test.xml")

xmlToList(doc)

$name

[1] "Test"

$description

[1] "Some Description"

相关阅读:
Top