Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Java XML document creation

Reply
Thread Tools

Java XML document creation

 
 
alfienorks@hotmail.com
Guest
Posts: n/a
 
      09-01-2005
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

 
Reply With Quote
 
 
 
 
jan V
Guest
Posts: n/a
 
      09-01-2005
> 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...


 
Reply With Quote
 
 
 
 
alfienorks@hotmail.com
Guest
Posts: n/a
 
      09-01-2005
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.

 
Reply With Quote
 
jan V
Guest
Posts: n/a
 
      09-01-2005
> 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.


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-01-2005
On 1 Sep 2005 09:36:11 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) 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.
 
Reply With Quote
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      09-02-2005
(E-Mail Removed) 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/...g/java/gui/faq
http://www.uni-giessen.de/faq/archiv....java.gui.faq/
 
Reply With Quote
 
alfienorks@hotmail.com
Guest
Posts: n/a
 
      09-02-2005
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;
}

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      09-02-2005
On 2 Sep 2005 08:01:25 -0700, (E-Mail Removed) 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'
 
Reply With Quote
 
jan V
Guest
Posts: n/a
 
      09-03-2005
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to (batch) set EXIF date taken and IPTC creation date and creation time for photos with filenames YYMMDDHHMMSS#.jpg? guercheLE@gmail.com Digital Photography 1 10-04-2005 07:15 PM
Refer to an XML document from within an XML document Manish Hatwalne XML 1 07-13-2004 10:24 AM
dynamic XML document creation Lerp ASP .Net 1 06-24-2004 03:45 AM
XML doc creation from XML schema & raw data Doug Day XML 0 06-22-2004 05:17 PM
Help on including one XML document within another XML document using XML Schemas Tony Prichard XML 0 12-12-2003 03:18 PM



Advertisments