Parsing XML will resolve Html -Entities ---But i don't want
843834Sep 17 2007 — edited Sep 19 2007Hi all,
i have some text in my xml-string with html-entities which i want to keep while parsing into a document. but after parsing, the xml entities will be resolved in real characters. what can i do to stop this resolving.
e.g.{color:#0000ff} i want to keep the entity daß and don't want to resolve it in daß{color}
{color:#0000ff}Sample XML-Text{color}
{color:#993366}
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<a>this is a german umlaut: da& #xDF; </a>{color}
{color:#0000ff}*Sample SourceCode:*{color}
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
public class test1 {
public static void main(String[] args) throws Exception
{
String xmldata="<?xml version=\"1.0\" encoding=\"UTF-8\"?><a>this is a german umlaut: da& #xDF;</a>";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc= null;
doc=builder.parse(new InputSource(new StringReader(xmldata)));
//Write to System.out
TransformerFactory tf = TransformerFactory.newInstance();
Transformer trans = tf.newTransformer();
trans.transform(new DOMSource(doc), new StreamResult(System.out));
}
}
the output is:
this is a german umlaut: da�
but i want:
this is a german umlaut: da& #xDF;
thanks for helping to find a solution
cu maxpade
Edited by: maxpade on Sep 17, 2007 5:07 AM