• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Removing encoding attribute from the <XML> element

 
Ranch Hand
Posts: 50
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am creating an XML file that will be used on the mainframe machine. But I have some issues with the generated XML file.

I am using the DOM object and XMLWriter class to generate the file. I am using following code




But this generates an XML file that looks like below :

<?xml version="1.0" encoding="UTF-8"?>
<root><doc><info><docDescription> blah blah.... </root>

But I want to remove the encoding="UTF-8" attribute and want the entire XML without any spaces/new line characters like below...
<?xml version="1.0"?><root><doc><info><docDescription> blah blah.... </root>


Does Anyone know how to achieve this???

Thanks in advance.....

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suppose you could write your own custom OutputStream to wrap FileOutputStream, substitute the <?xml version="1.0"> you want and then simply discard the formatting spaces, tabs, crlfs etc.

There are only a few methods in java.io.OutputStream that you would have to customize.

Bill
 
Sheriff
Posts: 27456
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see an XmlWriter class in the standard Java API. (I see an XmlWriter interface but it doesn't match what's in your code.) So is this somebody else's XmlWriter? Somebody else with a forum or a mailing list?
 
Srikanth Madasu
Ranch Hand
Posts: 50
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its a class from org.dom4j.io.* package...

documentation here
 
Paul Clapham
Sheriff
Posts: 27456
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, I see. So the documentation answers one of your questions when it says

The XML declaration and processing instructions are always on their own lines.



And it appears to answer the rest of your questions when it says

An OutputFormat object can be used to define how whitespace is handled when printing and allows various configuration options, such as to allow suppression of the XML declaration, the encoding declaration or whether empty documents are collapsed.



So apparently you need to do something different with the OutputFormat you are creating. I assume you're going through this exercise because the mainframe people have an XML parser which makes unreasonable demands about its input?
 
Srikanth Madasu
Ranch Hand
Posts: 50
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul, thanks for your reply... finally I figured the way to do it using OutputFormat object.

I kinda overlooked the documentation, thanks for pointing me to it.

Thanks!
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat().setOmitEncoding(true));
 
Sasparilla and fresh horses for all my men! You will see to it, won't you tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic