You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by Chris Gokey <cg...@hydrogen.stx.com> on 2000/02/28 02:34:08 UTC
How do I parse a DTD and access the element definitions?
Hi everyone,
I'm hoping that someone could point me in the right direction regarding what
classes I need in order to access element definitions in a DTD.
Consider the following DTD:
<!ELEMENT Personnel (Role+, First_Name?, Middle_Name?, Last_Name?,
Email*, Phone*, FAX*, Address?)>
<!ELEMENT Role (#PCDATA)>
<!ELEMENT First_Name (#PCDATA)>
<!ELEMENT Middle_Name (#PCDATA)>
<!ELEMENT Last_Name (#PCDATA)>
<!ELEMENT Email (#PCDATA)>
<!ELEMENT Phone (#PCDATA)>
<!ELEMENT FAX (#PCDATA)>
<!ELEMENT Address (#PCDATA)>
I'd like an API something like this:
// some class that would parse a DTD and create an intermediate representation
for
// accessing its elements (like a DOM).
DTDParser parser = new DTDParser();
parser.parse("dif.dtd");
ElementList list = parser.getElements();
int len = list.getLength();
for (int i=0; i<len; i++) {
String elementName = list.item(i).getElementName();
String definition = list.item(i).getDefintion();
System.out.println("elementName="+elementName);
System.out.println("definition="+defintion);
System.out.println("\n");
}
In which the code above might produce the following output:
elementName = Personnel
definition = (Role+, First_Name?, Middle_Name?, Last_Name?,
Email*, Phone*, FAX*, Address?)
elementName = Role
definition = (#PCDATA)
elementName = FirstName
defintion = (#PCDATA)
.
.
.
I would imagaine the Xerces library must have something to help me achieve
this functionality?
Thanks in advanced...
Chris
--
Christopher D. Gokey, Raytheon ITSS, NASA/GCMD
18 Martin Road, Shelburne Falls, MA 01370
Phone: Voice (413) 625-8129 / FAX 208-248-9055
cgokey@gcmd.nasa.gov / http://gcmd.nasa.gov