help!how could i change dom's encoding using jaxp?

Discussions

XML & Web services: help!how could i change dom's encoding using jaxp?

  1. help!how could i change dom's encoding using jaxp? (1 messages)

    when i am creating an dom,i want to specify the encoding as "gb2312",i do the following:

    Node encodeNode=document.createProcessingInstruction("xml","encoding=\"gb2312\"");
    document.appendChild(encodeNode);

    but when i check the produced xml file,i found both the following node existing:
      <?xml version="1.0" encoding="UTF-8"?>
      <?xml encoding="gb2312"?>
    i can't find method to trim the first code line using jaxp,what should i do?
  2. I am assuming you output your DOM using a Transformer (the standard JAXP approach). Add these lines after you create the transformer:

    Properties props = new Properties();
    props.put("encoding", "gb2312");
    transformer.setOutputProperties(props);

    This will do the trick. You don't need to add the processing instruction.

    Gal