Loading ...
Sorry, an error occurred while loading the content.

New Line in an xml document

Expand Messages
  • bharathi kongara
    Hey, I m trying to insert a new line into an xml document directly, with the following code: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    Message 1 of 3 , Jun 5 8:27 AM
    • 0 Attachment
      Hey,

      I'm trying to insert a new line into an xml document
      directly, with the following code:

      DocumentBuilderFactory dbf =
      DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();

      Document outputDoc = db.newDocument();

      // Creating the root element DOCUMENT
      Element dcmt =
      outputDoc.createElement("DOCUMENT");

      dcmt.appendChild(outputDoc.createTextNode("before the
      newline"));

      dcmt.appendChild(outputDoc.createTextNode(" "));

      dcmt.appendChild(outputDoc.createTextNode("after the
      new line"));

      outputDoc.appendChild(dcmt);

      But it never inserted a newline, it only inserted the
      text " " directly! Any ideas?

      Thanks,
      Bharathi

      __________________________________________________
      Do You Yahoo!?
      Tired of spam? Yahoo! Mail has the best spam protection around
      http://mail.yahoo.com
    • G. Ken Holman
      This is not an XSL-FO question. ... Yes, please ask the question in a more appropriate forum. . . . . . . . . . . . Ken -- Registration open for XSLT/XSL-FO
      Message 2 of 3 , Jun 5 8:59 AM
      • 0 Attachment
        This is not an XSL-FO question.

        At 2006-06-05 08:27 -0700, you wrote:
        >I'm trying to insert a new line into an xml document
        >directly, with the following code:
        >...
        >But it never inserted a newline, it only inserted the
        >text " " directly! Any ideas?

        Yes, please ask the question in a more appropriate forum.

        . . . . . . . . . . . Ken

        --
        Registration open for XSLT/XSL-FO training: Wash.,DC 2006-06-12/16
        Also for XSL-FO/XSLT training: Minneapolis, MN 2006-07-31/08-04
        Also for XML/XSLT/XSL-FO/UBL training: Varo,Denmark 06-09-25/10-06
        World-wide corporate, govt. & user group UBL, XSL, & XML training.
        G. Ken Holman mailto:gkholman@...
        Crane Softwrights Ltd. http://www.CraneSoftwrights.com/f/
        Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
        Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/f/bc
        Legal business disclaimers: http://www.CraneSoftwrights.com/legal
      • J.Pietschmann
        ... You got exactly what you asked. In order to get a newline, try dcmt.appendChild(outputDoc.createTextNode( n )); J.Pietschmann
        Message 3 of 3 , Jun 5 4:10 PM
        • 0 Attachment
          bharathi kongara wrote:
          > I'm trying to insert a new line into an xml document
          ...
          > dcmt.appendChild(outputDoc.createTextNode(" "));
          ...
          > But it never inserted a newline, it only inserted the
          > text " " directly! Any ideas?

          You got exactly what you asked.
          In order to get a newline, try
          dcmt.appendChild(outputDoc.createTextNode("\n"));

          J.Pietschmann
        Your message has been successfully submitted and would be delivered to recipients shortly.