Java XML document creation

Discussion in 'Java' started by alfienorks@hotmail.com, Sep 1, 2005.

  1. Guest

    I'm new to XML document creation with Java and I've got to admit I'm
    struggling.

    I need to generate an XML file structure in Java (no content - just the
    structure) based on an array of parameters as follows:

    XMLNodesArray[] = { '/a/b/c', '/a/b/d', '/z/y/x', '/z/y/a' };

    and what I need is an (string) output of:

    <root>
    <a>
    <b>
    <c></c>
    <d></d>
    </b>
    </a>
    <z>
    <y>
    <x></x>
    <a></a>
    </y>
    </z>
    </root>

    Firstly is there a quick way of converting these slash delimited tokens
    into XML
    Alternatively is there a Java-XML-Document-Creation-101 guide anywhere
    that might tell me how to navigate a growing XML tree and insert
    missing tokens as I trawl through the XMLNodesArray?

    Any thoughts - or guidance on XML document generation coding?

    many thanks,
    Al
     
    , Sep 1, 2005
    #1
    1. Advertising

  2. jan V Guest

    > Any thoughts - or guidance on XML document generation coding?
    >
    > many thanks,


    There are (literally) stacks of books on XML, and there are almighty tangles
    of XML info on the web. I'd say, start reading...
     
    jan V, Sep 1, 2005
    #2
    1. Advertising

  3. Guest

    Jan V - I've looked at your other "helpful-comments" you've posted in
    the past ... if you haven't got anything useful to say then please
    don't say anything - most of your postings say "read a book" - well why
    don't you do that (do you happen to work for a publisher by any chance)
    and stay off the web as YOU ARE JUST NOT HELPING.
     
    , Sep 1, 2005
    #3
  4. jan V Guest

    > Jan V - I've looked at your other "helpful-comments" you've posted in
    > the past ... if you haven't got anything useful to say then please
    > don't say anything - most of your postings say "read a book" - well why
    > don't you do that (do you happen to work for a publisher by any chance)
    > and stay off the web as YOU ARE JUST NOT HELPING.


    Clearly I'm not helping you, ... that's not to say that many others could
    not react with "A book, for goodness sake, of course, I'll get myself a book
    on this and become an expert on the subject."

    I regard reading well-written technical books as a professional necessity,
    and I regard anyone claiming to be part of our profession who refuses to
    read same as thoroughly outside the profession. Your opinion on this issue
    may of course differ.
     
    jan V, Sep 1, 2005
    #4
  5. Roedy Green Guest

    On 1 Sep 2005 09:36:11 -0700, wrote or quoted :

    >XMLNodesArray[] = { '/a/b/c', '/a/b/d', '/z/y/x', '/z/y/a' };


    this notation so far as I know is something you cooked up, and empty
    data files are not something there is a big demand for. So I will
    hazard a guess you wont' find a canned solution.

    Tackling the problem from scratch, here is how I would proceed.

    1. use regex to convert a/b/c to new String[]{ "a", "b", "c" };

    2. write some looping code to convert that to
    <root>
    <a>
    <b>
    <c></c>
    </b>
    </a>
    </root>

    3. write some looping code to convert two lines '/a/b/c', '/a/b/d' to
    what you want.

    4. keep going, adding more lines until you see the general patterns.



    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Sep 1, 2005
    #5
  6. wrote:
    > Jan V - I've looked at your other "helpful-comments" you've posted in
    > the past ... if you haven't got anything useful to say then please
    > don't say anything - most of your postings say "read a book" - well why
    > don't you do that (do you happen to work for a publisher by any chance)
    > and stay off the web as YOU ARE JUST NOT HELPING.


    This is not a help desk. This is a discussion group. If you need
    predictable help consider paying someone. Whining will not help either.

    /Thomas
    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
     
    Thomas Weidenfeller, Sep 2, 2005
    #6
  7. Guest

    Thanks Roedy, but I think I've got the solution (the problem I had was
    virtually nobody talked about creating XML - they only focused on
    reading it) - anyway I'm not sure if I should simply send everyone to a
    book to read up on (which works if we all have access to that book - or
    shall I just post the solution so that anyone reading the web at the
    moment can see). What do you think Jan - shall I help - or shall I just
    be painful and suggest anyone needing a quick solution goes to the
    library for a couple of days?

    [This next part is not directed to Roedy] This is a discussion group
    with people with real world problems looking for help, pointers,
    suggestions and code examples - not responses from people that have
    nothing better to do than lord over newsgroups in the vain belief that
    they know best without actually helping and all they are doing is
    cluttering up the web with their useless verbiage. ToW/JaV (if you're
    not the same person) - please continue to clutter up this thread with
    things nobody wants to read (probably suggesting we read a book on what
    website to surf on another lonely Saturday night) as I will not be
    watching it now.
    Perhaps if Jan can look/go away then I'll post the code,




    private String test(Vector slashtags) throws Exception {

    String output = "";

    Element tree = new Element("root");
    Element elements = style;
    String ftp = "";
    String list = "";
    String tag = "";

    Enumeration enum = slashtags.elements();
    while (enum.hasMoreElements()) {
    slashList = (String) enum.nextElement();
    StringTokenizer st = new StringTokenizer(slashList, "/");

    elements = style;
    while (st.hasMoreElements()) {
    tag = (String) st.nextElement();
    List list = elements.getChildren();
    Element tagElement = new Element(tag);

    boolean found = false;
    for (int i= 0; i< list.size(); i++) {
    if (((Element)
    list.get(i)).getName().equals(tagElement)) {
    found = true;
    }
    }
    if (!found) {
    elements.addContent(newElement);
    }

    elements = elements.getChild(tagElement);
    }

    }

    // Return an XML looking string based on the Element tree...
    return getEString(tree);
    }


    private String getEString(Element tree) throws Exception {

    String result = "";
    XMLOutputter serializer = new XMLOutputter();
    result = serializer.outputString(tree);
    return result;
    }
     
    , Sep 2, 2005
    #7
  8. On 2 Sep 2005 08:01:25 -0700, wrote:

    > [This next part is not directed to Roedy] This is a discussion group
    > with people with real world problems looking for help, pointers,
    > suggestions and code examples - not responses from people that have
    > nothing better to do than lord over newsgroups in the vain belief that
    > they know best without actually helping and all they are doing is
    > cluttering up the web with their useless verbiage. ToW/JaV (if you're
    > not the same person) - please continue to clutter up this thread with
    > things nobody wants to read (probably suggesting we read a book on what
    > website to surf on another lonely Saturday night) as I will not be
    > watching it now.
    > Perhaps if Jan can look/go away then I'll post the code,


    Perhaps you should grow up, instead.

    jan V gets straight to the point. If you don't like that,
    maybe you need to find a 'nice forum'[1].

    As an aside, those who know of the many helpful postings[2]
    by jan V would recognise that your complaints are merely the
    rantings of a tempramental, self centered, immature person
    who mistakes this forum for a help desk.

    [2] A sample of recent posts..
    <http://groups.google.com/group/comp.lang.java.programmer/msg/64978aea76c9d892>
    <http://groups.google.com/group/comp.lang.java.programmer/msg/08c06d0f2a6374cc>
    <http://groups.google.com/group/comp.lang.java.programmer/msg/2ab521f20822d1ad>
    <http://groups.google.com/group/comp.lang.java.programmer/msg/739aa5761a4f728b>

    [1] <http://www.physci.org/codes/javafaq.jsp#cljh>

    --
    Andrew Thompson
    physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
    "The shackles of commitment fell, in pieces on the ground"
    Led Zeppelin 'Achilles Last Stand'
     
    Andrew Thompson, Sep 2, 2005
    #8
  9. jan V Guest

    > moment can see). What do you think Jan - shall I help - or shall I just
    > be painful and suggest anyone needing a quick solution goes to the
    > library for a couple of days?


    My dear fellow, you have a strange perspective on showing gratitude.

    When you come to any newsgroup asking questions, then all those who respond
    to your post with any productive advice whatsoever (whether it's advice you
    agree with, or not) are trying to help *you*.

    In any culture, helping your fellow man is called being generous, and in any
    culture, generosity received by a polite individual deserves the expression
    of gratitude. What you're doing is biting the hand that feeds you, so like
    Andrew correctly points out, that's gross immaturity.

    Now, if you don't mind, I fancy helping a few other people stay on the rails
    of good software engineering while using Java as an implementation language.
     
    jan V, Sep 3, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lerp

    dynamic XML document creation

    Lerp, Jun 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    445
    Oleg Ogurok
    Jun 24, 2004
  2. Tony Prichard
    Replies:
    0
    Views:
    791
    Tony Prichard
    Dec 12, 2003
  3. Doug Day
    Replies:
    0
    Views:
    398
    Doug Day
    Jun 22, 2004
  4. Manish Hatwalne
    Replies:
    1
    Views:
    423
    Martin Honnen
    Jul 13, 2004
  5. Replies:
    4
    Views:
    715
Loading...

Share This Page