Created
November 10, 2012 21:44
-
-
Save 0guzhan/4052636 to your computer and use it in GitHub Desktop.
javax.xml.stream.XMLStreamException: Underlying stream encoding 'Cp1254' and input paramter for writeStartDocument() method 'UTF-8' do not match.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
import javax.xml.stream.XMLStreamException; | |
import org.apache.axiom.om.OMAbstractFactory; | |
import org.apache.axiom.om.OMAttribute; | |
import org.apache.axiom.om.OMDocument; | |
import org.apache.axiom.om.OMElement; | |
import org.apache.axiom.om.OMFactory; | |
import org.apache.axiom.om.OMNamespace; | |
public class AxiomProgrammatically { | |
public static void main(String[] args) { | |
//Obtain a factory | |
OMFactory factory = OMAbstractFactory.getOMFactory(); | |
//use the factory to create two namespace object | |
OMNamespace versionNS = factory.createOMNamespace("http://0guzhan.blogspot.com/axiom/v1","v1"); | |
OMAttribute attribute = factory.createOMAttribute("uniqueId", versionNS, "0-123-456-789"); | |
//use the factory to create three elements to represent the book element | |
OMElement book = factory.createOMElement("book",versionNS); | |
OMElement author = factory.createOMElement("author",versionNS); | |
author.addAttribute(attribute); | |
author.setText("Oguzhan Acargil"); | |
OMElement title = factory.createOMElement("title", versionNS); | |
title.setText("Axiom Basics"); | |
book.addChild(author); | |
book.addChild(title); | |
OMDocument document = factory.createOMDocument(); | |
document.setCharsetEncoding("UTF-8"); | |
document.setXMLVersion("1.0"); | |
document.addChild(book); | |
try { | |
document.serialize(System.out); | |
System.out.println(); | |
document.serialize(new FileWriter(new File("output.xml"))); | |
} catch (XMLStreamException e) { | |
// javax.xml.stream.XMLStreamException: Underlying stream encoding 'Cp1254' | |
// and input paramter for writeStartDocument() method 'UTF-8' do not match. | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment