[jdom-interest] DTD parser
J. Albers
jalbers at cs.uu.nl
Tue Feb 3 05:55:09 PST 2004
Hey all,
Is there a DTD parser in JDOM, and if so, does someone have an example of
some code how a DTD is written to a JTree? Right now i'm using another class
for the DTD and it writes to the console, but i have very much trouble
getting it right in a JTree. I'll show u some of the code.
Thanks, Joachim.
protected static void printElementTree(DTD dtd, DTDElement element,
String pad, Stack stack)
{
if (stack.contains(element.name))
{
System.out.println(pad+" -- "+element.name);
//Main.elements2.add(new DefaultMutableTreeNode(element.name));
return;
}
stack.push(element.name);
if (!(element.content instanceof DTDContainer))
{
System.out.println(pad+" -- "+element.name);
}
else
{
DTDItem[] items = ((DTDContainer) element.content).getItems();
Vector elems = new Vector();
for (int i=0; i < items.length; i++)
{
if (items[i] instanceof DTDContainer)
{
expandContainer((DTDContainer) items[i], elems, dtd);
continue;
}
else if (!(items[i] instanceof DTDName))
{
continue;
}
DTDElement currElem = (DTDElement) dtd.elements.get(
((DTDName) items[i]).value);
//Main.elements2.add(new DefaultMutableTreeNode(currElem.name));
if (currElem == null) continue;
elems.addElement(currElem);
}
if (elems.size() == 0)
{
System.out.println(pad);
// stack.pop();
return;
}
String pipePad = makePipePad(pad);
//DefaultMutableTreeNode node = new DefaultMutableTreeNode(null);
for (int i=0; i < elems.size(); i++)//moet elementen omdraaien.(nog
loepje maken)
{
DTDElement currElem = (DTDElement) elems.elementAt(i);
if (i == 0)
{//alleen alsals eerste(of enige)
printElementTree(dtd, currElem, pad+" -- "+currElem.name, stack);
}
else if (i < elems.size()-1)
{//als niet de laatste en niet de eerste
printElementTree(dtd, currElem, pipePad+" |- "+currElem.name, stack);
}
else
{//alleen de laatste
printElementTree(dtd, currElem, pipePad+" +- "+currElem.name, stack);
}
//Main.elements2.add(node);
}
}
// stack.pop();
}
More information about the jdom-interest
mailing list