DOCTYPE not created

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bill turner

    #1

    DOCTYPE not created

    I've searched the web and news groups. It seems others have had this
    problem. Unfortunately, the solution seems to be exactly what I've
    coded. If anybody can point out what is wrong, I'd truly appreciate
    it. What I am trying to do is to write an xml file to a local disk
    file. Everything else comes out just fine. However, the DOCTYPE node
    is not created. I've tried a number of different things, including
    specifying that I wanted a validating implementation, all to no avail.
    Here is a snippet of the relative code:

    <snippet>
    DocumentBuilder Factory builderFactory
    = DocumentBuilder Factory.newInst ance();
    builderFactory. setValidating(t rue);
    DocumentBuilder builder = builderFactory. newDocumentBuil der();
    DOMImplementati on impl = builder.getDOMI mplementation() ;
    //DocumentType docType =impl.createDoc umentType("trap batch",
    "","trapmonkey. dtd");
    DocumentType docType = impl.createDocu mentType("trapb atch",null,
    "trapmonkey.dtd ");

    //doc = impl.createDocu ment("", "trapbatch" , docType);
    doc = impl.createDocu ment(null, "trapbatch" , docType);

    rootElement = doc.getDocument Element();
    doc.insertBefor e(doc.createCom ment("a good rule of thumb is to use
    child elements rather than attributes if the information feels like
    data"), rootElement);
    rootElement.app endChild(doc.cr eateComment("en terpriseSpecfic Traps"));
    rootElement.app endChild(doc.cr eateComment("if repeat attribute = 0,
    the the delayInMillis attribute is meaningless. The The delayInMillis
    attribute is defaulted by the application in all other situations"));

    for (int i = 0; i < this.size(); i++)
    {
    trap = this.get(i);

    trapElement = doc.createEleme nt("trap");
    trapElement.set Attribute("repe at", trap.getRepeat( ));

    trapElement.set Attribute("dela yInMillis",trap .getDelayInMill iseconds());

    rootElement.app endChild(trapEl ement);
  • Philippe Poulard

    #2
    Re: DOCTYPE not created

    bill turner wrote:[color=blue]
    > I've searched the web and news groups. It seems others have had this
    > problem. Unfortunately, the solution seems to be exactly what I've
    > coded. If anybody can point out what is wrong, I'd truly appreciate
    > it. What I am trying to do is to write an xml file to a local disk
    > file. Everything else comes out just fine. However, the DOCTYPE node
    > is not created. I've tried a number of different things, including
    > specifying that I wanted a validating implementation, all to no avail.
    > Here is a snippet of the relative code:
    >
    > <snippet>
    > DocumentBuilder Factory builderFactory
    > = DocumentBuilder Factory.newInst ance();
    > builderFactory. setValidating(t rue);
    > DocumentBuilder builder = builderFactory. newDocumentBuil der();
    > DOMImplementati on impl = builder.getDOMI mplementation() ;
    > //DocumentType docType =impl.createDoc umentType("trap batch",
    > "","trapmonkey. dtd");
    > DocumentType docType = impl.createDocu mentType("trapb atch",null,
    > "trapmonkey.dtd ");
    >
    > //doc = impl.createDocu ment("", "trapbatch" , docType);
    > doc = impl.createDocu ment(null, "trapbatch" , docType);
    >
    > rootElement = doc.getDocument Element();
    > doc.insertBefor e(doc.createCom ment("a good rule of thumb is to use
    > child elements rather than attributes if the information feels like
    > data"), rootElement);
    > rootElement.app endChild(doc.cr eateComment("en terpriseSpecfic Traps"));
    > rootElement.app endChild(doc.cr eateComment("if repeat attribute = 0,
    > the the delayInMillis attribute is meaningless. The The delayInMillis
    > attribute is defaulted by the application in all other situations"));
    >
    > for (int i = 0; i < this.size(); i++)
    > {
    > trap = this.get(i);
    >
    > trapElement = doc.createEleme nt("trap");
    > trapElement.set Attribute("repe at", trap.getRepeat( ));
    >
    > trapElement.set Attribute("dela yInMillis",trap .getDelayInMill iseconds());
    >
    > rootElement.app endChild(trapEl ement);
    > .
    > .
    > .
    > }
    >
    > TransformerFact ory tFactory =
    > TransformerFact ory.newInstance ();
    > Transformer transformer = tFactory.newTra nsformer();[/color]

    hi,

    the problem comes from the serializer : the default transformer just
    perform a copy ; in xslt, the public and system ids must be set
    explicitely :

    Transformer transformer = tFactory.newTra nsformer( myStylesheet );

    myStylesheet must be a stylesheet that performs a copy AND indicates the
    output format :

    <xsl:output
    doctype-public = string
    doctype-system = string
    />

    an other solution is to use another serializer instead of xslt's
    [color=blue]
    > DOMSource source = new DOMSource(doc);
    > StreamResult result = new StreamResult(ne w
    > File(System.get Property("user. dir") +
    > System.getPrope rty("file.separ ator") +
    > TrapBatch.TRAP_ TEMPLATE_TEST_F ILE));
    > transformer.tra nsform(source, result);
    >
    >
    > </snippet>
    >
    > Again, thanks for your help!
    >
    > Bill[/color]


    --
    Cordialement,

    ///
    (. .)
    -----ooO--(_)--Ooo-----
    | Philippe Poulard |
    -----------------------

    Comment

    • Philippe Poulard

      #3
      Re: DOCTYPE not created

      Philippe Poulard wrote:[color=blue]
      > bill turner wrote:
      >[color=green]
      >> I've searched the web and news groups. It seems others have had this
      >> problem. Unfortunately, the solution seems to be exactly what I've
      >> coded. If anybody can point out what is wrong, I'd truly appreciate
      >> it. What I am trying to do is to write an xml file to a local disk
      >> file. Everything else comes out just fine. However, the DOCTYPE node
      >> is not created. I've tried a number of different things, including
      >> specifying that I wanted a validating implementation, all to no avail.
      >> Here is a snippet of the relative code:
      >>
      >> <snippet>
      >> DocumentBuilder Factory builderFactory =
      >> DocumentBuilder Factory.newInst ance();
      >> builderFactory. setValidating(t rue);
      >> DocumentBuilder builder = builderFactory. newDocumentBuil der();
      >> DOMImplementati on impl = builder.getDOMI mplementation() ;
      >> //DocumentType docType =impl.createDoc umentType("trap batch",
      >> "","trapmonkey. dtd");
      >> DocumentType docType = impl.createDocu mentType("trapb atch",null,
      >> "trapmonkey.dtd ");
      >>
      >> //doc = impl.createDocu ment("", "trapbatch" , docType);
      >> doc = impl.createDocu ment(null, "trapbatch" , docType);
      >>
      >> rootElement = doc.getDocument Element();
      >> doc.insertBefor e(doc.createCom ment("a good rule of thumb is to use
      >> child elements rather than attributes if the information feels like
      >> data"), rootElement);
      >> rootElement.app endChild(doc.cr eateComment("en terpriseSpecfic Traps"));
      >> rootElement.app endChild(doc.cr eateComment("if repeat attribute = 0,
      >> the the delayInMillis attribute is meaningless. The The delayInMillis
      >> attribute is defaulted by the application in all other situations"));
      >>
      >> for (int i = 0; i < this.size(); i++)
      >> {
      >> trap = this.get(i);
      >>
      >> trapElement = doc.createEleme nt("trap");
      >> trapElement.set Attribute("repe at", trap.getRepeat( ));
      >>
      >> trapElement.set Attribute("dela yInMillis",trap .getDelayInMill iseconds());
      >>
      >> rootElement.app endChild(trapEl ement);
      >> .
      >> .
      >> .
      >> }
      >>
      >> TransformerFact ory tFactory =
      >> TransformerFact ory.newInstance ();
      >> Transformer transformer = tFactory.newTra nsformer();[/color]
      >
      >
      > hi,
      >
      > the problem comes from the serializer : the default transformer just
      > perform a copy ; in xslt, the public and system ids must be set
      > explicitely :
      >
      > Transformer transformer = tFactory.newTra nsformer( myStylesheet );
      >
      > myStylesheet must be a stylesheet that performs a copy AND indicates the
      > output format :
      >
      > <xsl:output
      > doctype-public = string
      > doctype-system = string
      > />
      >
      > an other solution is to use another serializer instead of xslt's
      >[/color]

      there is a more convenient way : JAXP provides a mean to set the public
      and system id directly ; try something like this :

      Transformer transformer = tFactory.newTra nsformer();
      transformer.set OutputProperty( OutputKeys.DOCT YPE_SYSTEM, "trapmonkey.dtd ");

      [color=blue][color=green]
      >> DOMSource source = new DOMSource(doc);
      >> StreamResult result = new StreamResult(ne w
      >> File(System.get Property("user. dir") +
      >> System.getPrope rty("file.separ ator") +
      >> TrapBatch.TRAP_ TEMPLATE_TEST_F ILE));
      >> transformer.tra nsform(source, result);
      >>
      >>
      >> </snippet>
      >>
      >> Again, thanks for your help!
      >>
      >> Bill[/color]
      >
      >
      >[/color]


      --
      Cordialement,

      ///
      (. .)
      -----ooO--(_)--Ooo-----
      | Philippe Poulard |
      -----------------------

      Comment

      • bill

        #4
        Re: DOCTYPE not created

        Philippe Poulard <Philippe.Poula rdNO@SPAMsophia .inria.fr> wrote in message news:<cl7ph8$o6 l$1@news-sop.inria.fr>.. .[color=blue]
        > Philippe Poulard wrote:[color=green]
        > > bill turner wrote:
        > >[color=darkred]
        > >> I've searched the web and news groups. It seems others have had this
        > >> problem. Unfortunately, the solution seems to be exactly what I've
        > >> coded. If anybody can point out what is wrong, I'd truly appreciate
        > >> it. What I am trying to do is to write an xml file to a local disk
        > >> file. Everything else comes out just fine. However, the DOCTYPE node
        > >> is not created. I've tried a number of different things, including
        > >> specifying that I wanted a validating implementation, all to no avail.
        > >> Here is a snippet of the relative code:
        > >>
        > >> <snippet>
        > >> DocumentBuilder Factory builderFactory =
        > >> DocumentBuilder Factory.newInst ance();
        > >> builderFactory. setValidating(t rue);
        > >> DocumentBuilder builder = builderFactory. newDocumentBuil der();
        > >> DOMImplementati on impl = builder.getDOMI mplementation() ;
        > >> //DocumentType docType =impl.createDoc umentType("trap batch",
        > >> "","trapmonkey. dtd");
        > >> DocumentType docType = impl.createDocu mentType("trapb atch",null,
        > >> "trapmonkey.dtd ");
        > >>
        > >> //doc = impl.createDocu ment("", "trapbatch" , docType);
        > >> doc = impl.createDocu ment(null, "trapbatch" , docType);
        > >>
        > >> rootElement = doc.getDocument Element();
        > >> doc.insertBefor e(doc.createCom ment("a good rule of thumb is to use
        > >> child elements rather than attributes if the information feels like
        > >> data"), rootElement);
        > >> rootElement.app endChild(doc.cr eateComment("en terpriseSpecfic Traps"));
        > >> rootElement.app endChild(doc.cr eateComment("if repeat attribute = 0,
        > >> the the delayInMillis attribute is meaningless. The The delayInMillis
        > >> attribute is defaulted by the application in all other situations"));
        > >>
        > >> for (int i = 0; i < this.size(); i++)
        > >> {
        > >> trap = this.get(i);
        > >>
        > >> trapElement = doc.createEleme nt("trap");
        > >> trapElement.set Attribute("repe at", trap.getRepeat( ));
        > >>
        > >> trapElement.set Attribute("dela yInMillis",trap .getDelayInMill iseconds());
        > >>
        > >> rootElement.app endChild(trapEl ement);
        > >> .
        > >> .
        > >> .
        > >> }
        > >>
        > >> TransformerFact ory tFactory =
        > >> TransformerFact ory.newInstance ();
        > >> Transformer transformer = tFactory.newTra nsformer();[/color]
        > >
        > >
        > > hi,
        > >
        > > the problem comes from the serializer : the default transformer just
        > > perform a copy ; in xslt, the public and system ids must be set
        > > explicitely :
        > >
        > > Transformer transformer = tFactory.newTra nsformer( myStylesheet );
        > >
        > > myStylesheet must be a stylesheet that performs a copy AND indicates the
        > > output format :
        > >
        > > <xsl:output
        > > doctype-public = string
        > > doctype-system = string
        > > />
        > >
        > > an other solution is to use another serializer instead of xslt's
        > >[/color]
        >
        > there is a more convenient way : JAXP provides a mean to set the public
        > and system id directly ; try something like this :
        >
        > Transformer transformer = tFactory.newTra nsformer();
        > transformer.set OutputProperty( OutputKeys.DOCT YPE_SYSTEM, "trapmonkey.dtd ");
        >
        >[color=green][color=darkred]
        > >> DOMSource source = new DOMSource(doc);
        > >> StreamResult result = new StreamResult(ne w
        > >> File(System.get Property("user. dir") +
        > >> System.getPrope rty("file.separ ator") +
        > >> TrapBatch.TRAP_ TEMPLATE_TEST_F ILE));
        > >> transformer.tra nsform(source, result);
        > >>
        > >>
        > >> </snippet>
        > >>
        > >> Again, thanks for your help!
        > >>
        > >> Bill[/color]
        > >
        > >
        > >[/color][/color]

        Thanks! That last piece solved the problem (I didn't try your first
        suggestion). I spent days researching this. What a relief! Thanks
        again, Philippe!

        Bill

        Comment

        Working...