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.