You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "Hellmann Peter (ext) ICM RDC IS VDR RD" <Pe...@mch.siemens.de> on 2002/04/04 15:59:10 UTC

AW: Setting a DOCTYPE Declaration through DocumentType for a bran d ne w document

setDoctype() does the job !

/**
   * Gets the xml
   *
   * @return          the xml or "no valid document"
   * @exception       Standard exception "Exception" will be thrown
   *
   */

  public String GetXml()
  {

    if (null == document)
       {
       return "no valid document, cannot serialize DOM tree";
       }

    OutputFormat oformat = new OutputFormat(document);

    oformat.setDoctype(null, document.getDoctype().getSystemId());
    oformat.setLineWidth(80);
    oformat.setIndent(2);
    oformat.setLineSeparator("\r\n");
    oformat.setPreserveSpace(false);
    oformat.setOmitComments(false);
    oformat.setOmitDocumentType(false);
    oformat.setOmitXMLDeclaration(false);
    oformat.setEncoding(encType);
    oformat.setVersion("1.0");
    oformat.setStandalone(true);
    oformat.setIndenting(true);
    oformat.setPreserveEmptyAttributes(true);

    StringWriter stringOut = new StringWriter();

    try
    {

      XMLSerializer serial = new XMLSerializer(stringOut, oformat);
      serial.asDOMSerializer();

      serial.serialize(document);

    }
    catch (Exception e)
    {
      e.printStackTrace(System.err);
    }

    return stringOut.toString();
  }

> -----Ursprüngliche Nachricht-----
> Von: Hand, Brian [ mailto:b.hand@TriCorInd.com
<ma...@TriCorInd.com> ]
> Gesendet: Mittwoch, 3. April 2002 23:45
> An: 'xerces-j-user@xml.apache.org'
> Betreff: Setting a DOCTYPE Declaration through DocumentType
> for a brand
> ne w document
>
>
> Hi all,
>
> Being somewhat a newbie to Xerces I would like a create a
> document (via a
> save function) and I would like to set the <!DOCTYPE ....
> statement in the
> document to be saved.  I see that there are no setters in the
> DocumentType
> interface and was just wondering if someone could offer a
> quick snippet of
> code on how to set the <!DOCTYPE into the generated document.
>
> BTW I am using the DOM API.
>
> Thanks
> Brian
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>