Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

from XML doc to DTD

Posted on 2004-04-29
4
Medium Priority
?
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Accepted Solution

by:
joshuasherlock earned 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video teaches viewers about errors in exception handling.
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…
Suggested Courses

721 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