"Iban Torres" <[EMAIL PROTECTED]> writes:

> Is there any way to get an Array (or similar) with the Elements that
> a DTD have?, or should you parse the file with String methods?

Hmm...  If you parse a document, you can get information about its
schema, but it appears to be an undocumented extention.  You have to
set the following feature to true:
"http://apache.org/xml/features/domx/grammar-access";

Then you can get the associated elements from the DocumentType of a
parsed docuemnt.  Here is a function I used to do this (modified
slightly from my use, and therefore untested):

  public Map makeElementMap(DocumentType type) {
    NodeList nl = type.getChildNodes();
    Node n;
    for (int i = 0; i < nl.getLength(); i++) {
      n = nl.item(i);
      if (n.getNodeName().equals("schema")) {
        Element schema = (Element)n;
        NodeList elements = schema.getChildNodes();
        Map elementMap = new Hashtable(elements.getLength() * 2);
        for (int j = 0; j < elements.getLength(); j++) {
          Node nn = elements.item(j);
          if (nn.getNodeType() == Node.ELEMENT_NODE && 
              nn.getNodeName().equals("element")) {
            Element e = (Element)nn;
            String name = e.getAttribute("name");
            elementMap.put(name, e);
          }
        }
        return elementMap;
      }
    }
    throw new Error("No schema attached to this document type.");
  }

-- 
Michael Welsh Duggan
([EMAIL PROTECTED])

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to