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 Xiaoling Zhen <xi...@firsthop.com> on 2002/02/14 13:25:01 UTC
serializing processing instruction
Hi:
I want to get a xml such as following:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP
2.0//EN"
"http://www.wapforum.org/DTD/pap_2.0.dtd"
[<?wap-pap-ver supported-version="1.0,2.0"?>]>
<pap />
Result get by using my own code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP
2.0//EN"
"http://www.wapforum.org/DTD/pap_2.0.dtd">
<pap />
<?wap-pap-ver supported-version="1.0,2.0"?>
Source code:
OutputFormat format = new OutputFormat("xml", "UTF-8",
true);
format.setOmitXMLDeclaration(false);
format.setOmitDocumentType(false);
XMLSerializer xmlSer = new XMLSerializer(format);
try {
DocumentBuilder builder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
DOMImplementation domImpl =
builder.getDOMImplementation();
DocumentType doctype = domImpl.createDocumentType("pap",
"-//WAPFORUM//DTD PAP 2.0//EN",
"http://www.wapforum.org/DTD/pap_2.0.dtd");
Document doc = domImpl.createDocument(null, "pap",
doctype);
ProcessingInstruction pin =
doc.createProcessingInstruction("wap-pap-ver",
"supported-version=\"1.0,2.0\"");
doc.appendChild(pin);
synchronized(xmlSer) {
xmlSer.reset();
xmlSer.setOutputByteStream(out);
xmlSer.serialize(doc);
}
} catch(Exception e) {
e.printStackTrace();
}
How should I do to move the processing instruction into the
document type ?
Thanks for help!
XiaoLing Zhen
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org