Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2005

Tip: Looking for answers? Try searching our database.

how to build xml documents

Thread view: 
Dom - 16 Sep 2005 14:07 GMT
Hi to everyone,
I'm developing a java application that:
A) read some values from a database
B) build an XML file according to a specific DTD

Is there any open source library/component allowing to create an XML
document (file), like that:

doc.startdocument();
doc.startelement("A");
doc.startelement("B");
doc.startelement("C");
doc.addValue("cccccc");
doc.endelement("C");
doc.startelement("D");
doc.addValue("dddddd");
doc.endelement("D");
doc.endelement("B");
doc.endelement("A");
doc.endDocument();

to generate this file:
<A>
<B>
<C> cccccc </C>
<D> ddddd </D>
</B>
</A>

thanks
bye dom
Oliver Wong - 16 Sep 2005 17:01 GMT
> Hi to everyone,
> I'm developing a java application that:
> A) read some values from a database
> B) build an XML file according to a specific DTD
> Is there any open source library/component allowing to create an XML
> document (file), like that:

   We use Castor (http://www.castor.org/) to accomplish this. We've been
using it with XSDs, but there may be support for DTDs as well (haven't
checked). If not, it's open source, so you can add in support for DTDs, or
you can get a DTD to XSD converter.

   - Oliver
franco - 16 Sep 2005 17:53 GMT
A) database persistance is something you might want to look into, check
out hybernate.

B) try xmlbeans, in summary it takes a schema and compiles a package of
java classes that are bound to the schema definition, and methods that
allow serialization and parsing of xml text.

C) [your example] this looks like DOM.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder factory.newDocumentBuilder();

Document doc = builder.newDocument;

Element a = doc.createElement("A");
doc.appendChild(a);

Element b = doc.createElement("B");
a.appendChild(b);

Element c = doc.createElement("C");
c.appendChild(doc.createText("cccccc"));
b.appendChild(c);

Element d = doc.createElement("D");
d.appendChild(doc.createText("dddddd"));
b.appendChild(d);

is an example in DOM howto generate what you want.
Dom - 16 Sep 2005 18:30 GMT
Thanks very much to all.

I think I wille be applying solution 3 because:
A) data are derived from different datasources (file, databases, ...)
B) I haven't DTD or XSD

bye

> A) database persistance is something you might want to look into, check
> out hybernate.
[quoted text clipped - 25 lines]
>
> is an example in DOM howto generate what you want.
Oliver Wong - 16 Sep 2005 18:35 GMT
> B) I haven't DTD or XSD

   This seems to contradict your original post, in which you say:

> B) build an XML file according to a specific DTD

   - Oliver
franco - 22 Sep 2005 14:38 GMT
you should really look into using a document definition of some sort,
no matter which way you build xml, it should be valid when its done
being built
Roedy Green - 18 Sep 2005 09:32 GMT
>doc.startdocument();
>doc.startelement("A");
[quoted text clipped - 7 lines]
>doc.endelement("B");
>doc.endelement("A");

those methods are utterly trivial. If you don't want syntax checking
for balance, and other restrictions, you could implement them each
with a println statement.  You then can avoid downloading an XML
library.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.