Link to home
Start Free TrialLog in
Avatar of ousa
ousa

asked on

from XML doc to DTD

how to convert from XML document to DTD using jbuilder
i do the fooling but not yet could solve the problem

this program convert from db to xml (supposed to do that)

 out.write("<" + el.getNodeName() + ">");
          out.flush();

          for (int r = 0; r < tablesinfo[b].tsize; r++) {
            System.out.println("\n - r = " + r);
            System.out.println("\n - table parent = " +
                               tablesinfo[b].columns[r].parent);

            if (tablesinfo[b].columns[r].parent.compareTo(tablesinfo[b].tname) ==
                0) {
              if (tablesinfo[b].columns[r].ctype.compareTo("ID") == 0) {
                Attr attr = doc.createAttribute(tablesinfo[b].columns[r].cname);
                attr = el.setAttributeNode(attr);
                out.print("<" + tablesinfo[b].columns[r].cname + ">");
                out.flush();
                out.print("</" + tablesinfo[b].columns[r].cname + ">");
                out.flush();

              }
              else {
                // Create Table's original columns NODES!
                Element c = doc.createElement(tablesinfo[b].columns[r].cname);
                el.appendChild(c);
                out.print("<" + c.getNodeName() + ">");
                out.flush();
                out.print("</" + c.getNodeName() + ">");
                out.flush();

                Node parent = c.getParentNode();
                c = (Element) parent;
              }
            }
            else {
              // Create NEST Node's Nodes...
              nest[countnest] = tablesinfo[b].columns[r].parent;
              System.out.print(" - Subelement#" + countnest + nest[countnest] +
                               "has cols : ");
              countnest++;
              sube = doc.createElement(nest[countnest - 1]);
              el.appendChild(sube);
              out.print("<" + sube.getNodeName() + ">");
              out.flush();

              do {
                System.out.println("- Col#" + r + " is :" +
                                   tablesinfo[b].columns[r].cname);
                Element c = doc.createElement(tablesinfo[b].columns[r].cname);
                sube.appendChild(c);
                out.print("<" + c.getNodeName() + ">");
                out.flush();
                out.print("</" + c.getNodeName() + ">");
                out.flush();
                r++;
              }
              while ( (r < tablesinfo[b].tsize) &&
                     (tablesinfo[b].columns[r].
                      parent.compareTo(nest[countnest - 1]) == 0));
              out.print("</" + sube.getNodeName() + ">");
              out.flush();
              r--;
            }

          }
          out.write("</" + el.getNodeName() + ">");
          out.flush();
        }
      }

      out.print("</" + rootEl.getNodeName() + ">");
      out.flush();
      out.close();
    }

    catch (Exception e) {
      e.printStackTrace(System.err);
    } //end catch
  }
ASKER CERTIFIED SOLUTION
Avatar of joshuasherlock
joshuasherlock

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joshuasherlock
joshuasherlock

Thanks Modulo