My impression is that DocTypes are so rarely used these days that I'd rather not add them to the MarshallingContext API. This does make it a little more painful for people who need to use them, but at least it's still possible.

 - Dennis

Chris Hill wrote:

Very close, you have to call each marshalDocument call manually(plus setting output):
mctx.startDocument(...);
mctc.getXmlWriter().writeDocType(...);
mctx.marshalRoot(obj)
mctx.endDocument(...);


But since there are multiple marshalDocument methods this is probably not the most straightforward way of doing things. I've written a couple hooks into MarshallingContext and IMarshallingContext that I'm going to submit to Dennis:

setXmlDeclaration(boolean)-Sets whether or not to display the xmlDeclaration(I'm working with xml streams and don't want xml declarations mid-stream)

setDocTypeDeclaration(name,sys, pub, subset) - Sets the doctype of the document without requiring getting the xml writer, etc.

If you like I can send you a jibx-run.jar file with the changes, email me off-list!

Peace
C


Expedito Reinaldo da Silva J�nior wrote:

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] 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.



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/
_______________________________________________
jibx-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to