1

I'm currently using XMLStreamWriter to parse together an XML document. The only parameters that I'm allowed to pass in are "encoding" and "version", but I would like to have "standalone=no" in the declaration, as well. Here's what my output currently looks like:

<?xml version='1.0' encoding='UTF-8'?>

How can I make something like this?

<?xml version='1.0' encoding='UTF-8' standalone='no'?>
Jason Tu
  • 59
  • 1
  • 1
  • 7
  • You will need to post the Java code you're using – Jim Garrison Feb 28 '18 at 03:24
  • You are probably out of luck. The public API does not know about "standalone", and the most recent source I could find for the implementation (Java 6) contains the comment `// what about standalone?` – Jim Garrison Feb 28 '18 at 03:43

1 Answers1

1

XmlStreamWriter is an interface: it has more than one implementation!

If you install Saxon (any edition), you can create a Serializer using any of the serialization parameters defined in XSLT (for example standalone=yes), and then you can get an XmlStreamWriter that writes to this Serializer using Serializer.getXmlStreamWriter():

Processor p = new Processor(false);
Serializer s = p.newSerializer(System.out);
s.setOutputProperty(Property.STANDALONE, "no");
XmlStreamWriter writer = s.getXmlStreamWriter();
Michael Kay
  • 156,231
  • 11
  • 92
  • 164