Solved

from XML doc to DTD

Posted on 2004-04-29
4
212 Views
Last Modified: 2013-11-19
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
  }
0
Comment
Question by:ousa
  • 2
4 Comments
 

Accepted Solution

by:
joshuasherlock earned 125 total points
ID: 11012009
If you just want to create a one off DTD based on the XML you can try XMLSPY 2004 (www.altova.com). this will auto generate a DTD for you. However, as you are decided the format of the XML programatically you could write a generic DTD that defines the format that you expect your program to produce.

Another alternative is to use XSLT and your databases XML extensions (for example, the Oracle XDK with XSQL). First, you would  to extract the data from the database in a standard XML format then use XSL to transform the XML into your desired format. Would reduce the amount of coding needed but would require a bit of a learning curve on XSLT.

With more information on the nature of the problem I may be able to be more specific
0
 

Expert Comment

by:joshuasherlock
ID: 11709867
Thanks Modulo
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now