I have an issue with the marshalling on my JAXB and don’t quite understand why.
When I marshall out the data and add it to the xml file, all is correct except it imports the XML coding at the top.
Example of before:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<FlightDetails xmlns="http://xml.netbeans.org/schema/Shows">
<FlightDetailsCollection>
<DestinationCity>France</DestinationCity>
<ExtraInfo>Free Wifi</ExtraInfo>
<Date>2009-03-09</Date>
<Fare>
<CurrencyName>GBP</CurrencyName>
<CurrencyFare>60.0</CurrencyFare>
</Fare>
</FlightDetailsCollection>
</FlightDetails>
Then when I add the marshalled data it appears as so:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<FlightDetails xmlns="http://xml.netbeans.org/schema/Shows">
<FlightDetailsCollection>
<OriginCity>London</OriginCity>
<DestinationCity>France</DestinationCity>
<AirlineBrand>Ryan Air</AirlineBrand>
<ExtraInfo>Free Wifi</ExtraInfo>
<Date>2009-03-09</Date>
<Fare>
<CurrencyName>GBP</CurrencyName>
<CurrencyFare>60.0</CurrencyFare>
</Fare>
</FlightDetailsCollection>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<FlightDetails xmlns="http://xml.netbeans.org/schema/Shows">
<FlightDetailsCollection>
<OriginCity>Germany</OriginCity>
<DestinationCity>France</DestinationCity>
<AirlineBrand>Virgin Air</AirlineBrand>
<Date>2009-03-09</Date>
<Fare>
<CurrencyName>GBP</CurrencyName>
<CurrencyFare>200.0</CurrencyFare>
</Fare>
</FlightDetailsCollection>
</FlightDetails>
As you can see it’s added the following before putting it into the XML file.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<FlightDetails xmlns="http://xml.netbeans.org/schema/Shows">
How would I be able to stop it from including the encoding and schema name? In debug it seems to be only containing the needed information so I cant trace it. I presume it was JAXB adding it in, however could be wrong.
Many thanks,
You can do the following to omit the XML declaration:
I would create a StAX
XMLStreamWriterto wrap your output and keep marshalling to that which will help manage your namespace declarations and add a root element.