Hi,
Thanks for the helpfull response! But, I'm still having a little problem. If I generate the XML file with the code you informed, the resulting XML will have the DTD declaration followed by the 'XML declaration' (<?xml ... ?>), as it is described bellow:
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN" "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd"><?xml version="1.0" encoding="ISO-8859-1"?>
I realized that I can't call 'marshalDocument()' after 'writeDocType()', because it will always generate the XML declaration. So, what method should I call to generate a well formed XML??? I think I should try something like this:
IMarshallingContext mctx = getBindingFactory().createMarshallingContext();
FileOutputStream os = new FileOutputStream(file);
mctx.startDocument("UTF-8", null, os);
ctx.getXmlWriter().writeDocType(...);
// marshall method (???)
mctx.endDocument();
os.close();
Thanks,
Expedito.
-----Mensagem original-----
De: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]Em nome de Chris Hill
Enviada em: quarta-feira, 3 de novembro de 2004 18:53
Para: [EMAIL PROTECTED]
Assunto: Re: [jibx-users] XMLWriter Null
Hello,
If you're going to set the doctype, you are required to use an interim
step before you can get the xml writer. The xml writer does not exist
until you call marshalDocument(), you must call setOutput() first.
Something like:
MarshallingContext mc = bfactory.createMarshallingContext();
mc.setOutput(new FileOutputStream("myfile.xml");
IXMLWriter xw = mc.getWriter();
xw.writeDocType( name,sys, pub, subset);
mc.marshalDocument(myObj,"utf-8",null);
Cheers!
C
Expedito Reinaldo da Silva J�nior wrote:
> Hi,
>
> I'm very new to Jibx and I'm having a little problem when I try to
> access the XMLWriter so as I can declare a DTD. My code is below:
>
>
>
> 1 - IBindingFactory bfact =
> BindingDirectory.getFactory(rootObject.getClass());
> 2 -
> 3 - IMarshallingContext mctx = bfact.createMarshallingContext();
> 4 - mctx.setIndent(3);
> 5 -
> 6 - DTDDefinition dtd = ...; (not null)
> 7 - mctx.getXmlWriter().writeDocType(dtd.getRootElementName(),
> dtd.getSystemID(), dtd.getPublicID(),* **null*);
> 8 -
> 9 - mctx.marshalDocument(rootObject, "ISO-8859-1",* null*, xmlOut);
>
>
> P.S.: 'rootObject' is the object i'm trying to write to a XML file.
>
> But, on line 7 i'm getting a NullPointerException cause de XMLWriter
> is NULL!! Is there something wrong with my code????
>
> Thanks a lot!
>
> Expedito.
>
--
_________________________________________
< __ __ ____ >
< | | \/ ___\ Chris Hill >
< | | / /_/ > [EMAIL PROTECTED] >
< |____/\___ / http://ubergeek.tv >
< /_____/ The Smell of Geek! >
<----------------------------------------->
-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_idU88&alloc_id065&op=ick
_______________________________________________
jibx-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jibx-users
