I am using StAX parser for generating XML. Here is what I need to generate:
<?xml version = "1.0"?>
<!DOCTYPE FILE PUBLIC "-//SOMETHING//DTD bla bla bla//EN" "scheme.dtd"
[
<!ENTITY file1 SYSTEM "D:\repo\file1.pdf" NDATA application_pdf>
]
>
<FILES>
<FILE>
<METADATA></METADATA>
<CONTENT></CONTENT>
..... and so on .....
The problem is I don't know how to declare DOCTYPE and ENTITY tags. Tried to google it and didn't find any solutions. Please, help.
There is a method for this in the XMLStreamWriter class: writeDTD . Just pass the entire DOCTYPE blob into there.
I found the solution. I disabled characters escaping in factory:
XMLOutputFactory factory = XMLOutputFactory.newInstance();
factory.setProperty("escapeCharacters", false);
And wrote DOCTYPE and ENTITY using writeCharacters method:
writer.writeCharacters("doctype bla bla");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.