Yes, you can do this, though you'll have to have the latest version (3.x.x)
to do it. Look at the new EnumVal sample. It basically shows how to get an
enumerator for the various decl pools in the validator. Once you have that
enumerator, you can search it for the attribute or element you are
interested in. Then you can ask for the content model of the element. This
will give you the information you need in order to figure out the content
model.
If look inside the DTDElementDecl class, which is what represents an
element declaration in the DTD, you'll see that you can call getModelType()
to get the overall model type. From that, you can see if its ANY, EMPTY,
MIXED, or CHILDREN. If its CHILDREN, then you can call getContentSpecNode()
which will get you the root of a tree that represents the content model. If
you look inside the ContentSpecNode class, at the formatSpec() method,
you'll see how it iterates through that tree to reproduce the original DTD
content model, e.g. "(foo+,bar?,baz,bar)"
Let me know if you need any more information. Note that the content spec
nodes store element pool ids, not references to the element decls
themselves or text names, so you use the validator to look up that id in
order to get to the DTDElementDecl for the elements that are referenced in
the content model. The formatSpec() method shows all of this going on.
----------------------------------------
Dean Roddey
Software Weenie
IBM Center for Java Technology - Silicon Valley
[EMAIL PROTECTED]
"Wu, Kotien" <[EMAIL PROTECTED]> on 01/03/2000 05:14:09 AM
Please respond to [EMAIL PROTECTED]
To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
cc:
Subject: how get info from dtd
We have used IBM xml4c for validating xml syntax against its dtd and
validating context format (such as date, email ...) in xml since
June.
It runs great!
We have a question now: can we and how can we to get parsed dtd
info.
For example: we have an element name and an attribute name, can we
and how
can we to get its value for that attribute name from dtd:
___________________________________________________________________
<!ELEMENT specification (spec.title-block,specification-block) >
<!ATTLIST specification
id ID #REQUIRED
label CDATA #FIXED "[Specification] "
class CDATA #FIXED "legal-instrument" >
___________________________________________________________________
can we get [Specification](label value) using key word
"specification" (element name)and "label" (attribute name)
from dtd or get a parsed dtd, like xml (example SAXPrint gives
parsed xml)
Thanks!
Happy New Year !
Kotien Wu