Solved

from XML doc to DTD

Posted on 2004-04-29
4
207 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

747 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

12 Experts available now in Live!

Get 1:1 Help Now