Hello,

when constructing an XHTML document with Xerces-J, how to insert special
characters like " "? The problem is that the "&" character is replaced by
the """ sequence, thus " " is expanded to ""nbsp;".

There must be a way to insert special characters, but I have not been able to
figure it out.

Below is a simple test class and its output that demonstrate the problem.

Thanks, Andreas Hoenen

================================================================

import java.io.IOException;
import org.apache.html.dom.HTMLDocumentImpl;
import org.apache.html.dom.HTMLHeadingElementImpl;
import org.apache.html.dom.HTMLParagraphElementImpl;
import org.apache.xerces.dom.TextImpl;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XHTMLSerializer;
import org.w3c.dom.html.HTMLElement;
import org.w3c.dom.html.HTMLHeadingElement;

class XHtmlProblem
{
  static public void main( String[] args )
    throws IOException
  {
    HTMLDocumentImpl document = new HTMLDocumentImpl();

    document.setTitle( "XHTML ampersand problem" );

    HTMLElement body = document.getBody();

    HTMLHeadingElement heading = (HTMLHeadingElement) new 
HTMLHeadingElementImpl( document, "h1" );

    body.appendChild( heading );

    heading.appendChild( new TextImpl( document, "XHTML ampersand problem" ) );

    HTMLElement paragraph = new HTMLParagraphElementImpl( document, "p" );

    body.appendChild( paragraph );

    paragraph.appendChild( new TextImpl( document, "Belongs together." ) );

    paragraph = new HTMLParagraphElementImpl( document, "p" );

    body.appendChild( paragraph );

    paragraph.appendChild( new TextImpl( document, 
"Quoting\\ doesn't\\\\&help." ) );

    XHTMLSerializer serializer = new XHTMLSerializer( System.out, new 
OutputFormat() );

    serializer.serialize( document );
  }
}

================================================================

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/WD-html-in-xml/DTD/xhtml1-strict.dtd";>
<html><head><title>XHTML ampersand problem</title></head><body><h1>XHTML 
ampersand 
problem</h1><p>Belongs&amp;nbsp;together.</p><p>Quoting\&amp;nbsp;doesn't\\&amp;help.</p></body></html>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to