Read a Document Type Definition (DTD)

Share:

Description

Represents the contents of a DTD as a user-level object containing the element and entity definitions.

Usage

1
parseDTD(extId, asText=FALSE, name="", isURL=FALSE, error = xmlErrorCumulator())

Arguments

extId

The name of the file containing the DTD to be processed.

asText

logical indicating whether the value of ‘extId’ is the name of a file or the DTD content itself. Use this when the DTD is read as a character vector, before being parsed and handed to the parser as content only.

name

Optional name to provide to the parsing mechanism.

isURL

A logical value indicating whether the input source is to be considred a URL or a regular file or string containing the XML.

error

an R function that is called when an error is encountered. This can report it and continue or terminate by raising an error in R. See the error parameter for link{xmlTreeParse}.

Details

Parses and converts the contents of the DTD in the specified file into a user-level object containing all the information about the DTD.

Value

A list with two entries, one for the entities and the other for the elements defined within the DTD.

entities

a named list of the entities defined in the DTD. Each entry is indexed by the name of the corresponding entity. Each is an object of class XMLEntity or alternatively XMLExternalEntity if the entity refers to an external definition. The fields of these types of objects are

  • namethe name of the entity by which users refer to it.

  • contentthe expanded value or definition of the entity

  • originalthe value of the entity, but with references to other entities not expanded, but maintained in symbolic form.

elements

a named list of the elements defined in the DTD, with the name of each element being the identifier of the element being defined. Each entry is an object of class XMLElementDef which has 4 fields.

  • namethe name of the element.

  • typea named integer indicating the type of entry in the DTD, usually either element or mixed. The name of the value is a user-level type. The value is used for programming, both internally and externally.

  • contentsa description of the elements that can be nested within this element. This is an object of class XMLElementContent or one of its specializations - XMLSequenceContent, XMLOrContent. Each of these encodes the number of such elements permitted (one, one or more, zero or one, or zero or more); the type indicating whether the contents consist of a single element type, an ordered sequence of elements, or one of a set of elements. Finally, the actual contents description is described in the elements field. This is a list of one or more XMLElementContent, XMLSequenceContent and XMLOrContent objects.

  • attributesa named list of the attributes defined for this element in the DTD. Each element is of class XMLAttributeDef which has 4 fields.

    namename of the attribute, i.e. the left hand side

    typethe type of the value, e.g. an CDATA, Id, Idref(s), Entity(s), NMToken(s), Enumeration, Notation

    defaultTypethe defined type, one of None, Implied, Fixed or Required.

    defaultValuethe default value if it is specified, or the enumerated values as a character vector, if the type is Enumeration.

WARNING

Errors in the DTD are stored as warnings for programmatic access.

Note

Needs libxml (currently version 1.8.7)

Author(s)

Duncan Temple Lang <duncan@wald.ucdavis.edu>

References

http://www.w3.org

See Also

xmlTreeParse, WritingXML.html in the distribution.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
 dtdFile <- system.file("exampleData", "foo.dtd",package="XML")
 parseDTD(dtdFile)

txt <- readLines(dtdFile)
txt <- paste(txt,  collapse="\n")
d <- parseDTD(txt, asText=TRUE)


## Not run: 
 url <- "http://www.omegahat.net/XML/DTDs/DatasetByRecord.dtd"
 d <- parseDTD(url, asText=FALSE)  

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.