Setting xml encoding with documentbuilderfactory
hi everybody,
i have a problem with xml document generated by documentbuilderfactory class.
it seems that the default setting for the xml document encoding is UTF-8. i need to set this to UTF-16.
does anybody know how can i do this ?
thanx
Ale
http://forum.java.sun.com/thread.jsp?forum=34&thread=289433
Similar Messages
-
Set XML encoding by saving with Xerces
hi there,
i parse a xml dokument which is encoded by Cp1252. then i do a lot of modifications an want to write it back by using
OutputFormat format = new OutputFormat(XmlParser.document);
format.setLineSeparator(LineSeparator.Windows);
format.setIndenting(true);
format.setLineWidth(0);
format.setPreserveSpace(true);
XMLSerializer serializer;
try {
serializer = new XMLSerializer(new FileWriter(file), format);
serializer.asDOMSerializer();
serializer.serialize(XmlParser.document);
} catch (IOException e) {
e.printStackTrace();
}but this sets the encoding to UTF-8. what should i change to save it with Cp1252 encoding?use the -
OutputFormat(org.w3c.dom.Document doc, java.lang.String encoding, boolean indenting)
constructor with encoding="windows-1252".... -
How to set the Xml Encoding ISO-8859-1 to Transformer or DOMSource
I have a xml string and it already contains an xml declaration with encoding="ISO-8859-1". (In my real product, since some of the element/attribute value contains a Spanish character, I need to use this encoding instead of UTF-8.) Also, in my program, I need to add more attributes or manipulate the xml string dynamically, so I create a DOM Document object for that. And, then, I use Transformer to convert this Document to a stream.
My problme is: Firstly, once converted through the Transformer, the xml encoding changed to default UTF-8, Secondly, I wanted to check whether the DOM Document created with the xml string maintains the Xml Encoding of ISO-8859-1 or not. So, I called Document.getXmlEncoding(), but it is throwing a runtime error - unknown method.
Is there any way I can maintain the original Xml Encoding of ISO-8859-1 when I use either the DOMSource or Transformer? I am using JDK1.5.0-12.
Following is my sample program you can use.
I would appreciate any help, because so far, I cannot find any answer to this using the JDK documentation at all.
Thanks,
Jin Kim
import java.io.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Attr;
import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
public class XmlEncodingTest
StringBuffer xmlStrBuf = new StringBuffer();
TransformerFactory tFactory = null;
Transformer transformer = null;
Document document = null;
public void performTest()
xmlStrBuf.append("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n")
.append("<TESTXML>\n")
.append("<ELEM ATT1=\"Yes\" />\n")
.append("</TESTXML>\n");
// the encoding is set to iso-8859-1 in the xml declaration.
System.out.println("initial xml = \n" + xmlStrBuf.toString());
try
//Test1: Use the transformer to ouput the xmlStrBuf.
// This shows the xml encoding result from the transformer which will change to UTF-8
tFactory = TransformerFactory.newInstance();
transformer = tFactory.newTransformer();
StreamSource ss = new StreamSource( new StringBufferInputStream( xmlStrBuf.toString()));
System.out.println("Test1 result = ");
transformer.transform( ss, new StreamResult(System.out));
//Test2: Create a DOM document object for xmlStrBuf and manipulate it by adding an attribute ATT2="No"
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dfactory.newDocumentBuilder();
document = builder.parse( new StringBufferInputStream( xmlStrBuf.toString()));
// skip adding attribute since it does not affect the test result
// Use a Transformer to output the DOM document. the encoding becomes UTF-8
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(System.out);
System.out.println("\n\nTest2 result = ");
transformer.transform(source, result);
catch (Exception e)
System.out.println("<performTest> Exception caught. " + e.toString());
public static void main( String arg[])
XmlEncodingTest xmlTest = new XmlEncodingTest();
xmlTest.performTest();
}Thanks DrClap for your answer. With your information, I rewrote the sample program as in the following, and it works well now as I intended! About the UTF-8 and Spanish charaters, I think you are right. It looks like there can be many factors involved on this subject though - for example, the real character sets used to create an xml document, and the xml encoding information declared will matter. The special character I had a trouble was u00F3, and somehow, I found out that Sax Parser or even Document Builder parser does not like this character when encoding is set to "UTF-8" in the Xml document. My sample program below may not be a perfect example, but if you replaces ISO-8859-1 with UTF-8, and not setting the encoding property to the transfermer, you may notice that the special character in my example is broken in Test1 and Test2. In my sample, I decided to use ByteArrayInputStream instead of StringBufferInpuptStream because the documentation says StringBufferInputStream may have a problem with converting characters into bytes.
Thanks again for your help!
Jin Kim
import java.io.*;
import java.util.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Attr;
import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
* XML encoding test for Transformer
public class XmlEncodingTest2
StringBuffer xmlStrBuf = new StringBuffer();
TransformerFactory tFactory = null;
Document document = null;
public void performTest()
xmlStrBuf.append("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n")
.append("<TESTXML>\n")
.append("<ELEM ATT1=\"Resoluci�n\">\n")
.append("Special charatered attribute test")
.append("\n</ELEM>")
.append("\n</TESTXML>\n");
// the encoding is set to iso-8859-1 in the xml declaration.
System.out.println("**** Initial xml = \n" + xmlStrBuf.toString());
try
//TransformerFactoryImpl transformerFactory = new TransformerFactoryImpl();
//Test1: Use the transformer to ouput the xmlStrBuf.
tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
byte xmlbytes[] = xmlStrBuf.toString().getBytes("ISO-8859-1");
StreamSource streamSource = new StreamSource( new ByteArrayInputStream( xmlbytes ));
ByteArrayOutputStream xmlBaos = new ByteArrayOutputStream();
Properties transProperties = transformer.getOutputProperties();
transProperties.list( System.out); // prints out current transformer properties
System.out.println("**** setting the transformer's encoding property to ISO-8859-1.");
transformer.setOutputProperty("encoding", "ISO-8859-1");
transformer.transform( streamSource, new StreamResult( xmlBaos));
System.out.println("**** Test1 result = ");
System.out.println(xmlBaos.toString("ISO-8859-1"));
//Test2: Create a DOM document object for xmlStrBuf to add a new attribute ATT2="No"
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dfactory.newDocumentBuilder();
document = builder.parse( new ByteArrayInputStream( xmlbytes));
// skip adding attribute since it does not affect the test result
// Use a Transformer to output the DOM document.
DOMSource source = new DOMSource(document);
xmlBaos.reset();
transformer.transform( source, new StreamResult( xmlBaos));
System.out.println("\n\n****Test2 result = ");
System.out.println(xmlBaos.toString("ISO-8859-1"));
//xmlBaos.flush();
//xmlBaos.close();
catch (Exception e)
System.out.println("<performTest> Exception caught. " + e.toString());
finally
public static void main( String arg[])
XmlEncodingTest2 xmlTest = new XmlEncodingTest2();
xmlTest.performTest();
} -
Problems with reading XML files with ISO-8859-1 encoding
Hi!
I try to read a RSS file. The script below works with XML files with UTF-8 encoding but not ISO-8859-1. How to fix so it work with booth?
Here's the code:
import java.io.File;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.net.*;
* @author gustav
public class RSSDocument {
/** Creates a new instance of RSSDocument */
public RSSDocument(String inurl) {
String url = new String(inurl);
try{
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(url);
NodeList nodes = doc.getElementsByTagName("item");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList title = element.getElementsByTagName("title");
Element line = (Element) title.item(0);
System.out.println("Title: " + getCharacterDataFromElement(line));
NodeList des = element.getElementsByTagName("description");
line = (Element) des.item(0);
System.out.println("Des: " + getCharacterDataFromElement(line));
} catch (Exception e) {
e.printStackTrace();
public String getCharacterDataFromElement(Element e) {
Node child = e.getFirstChild();
if (child instanceof CharacterData) {
CharacterData cd = (CharacterData) child;
return cd.getData();
return "?";
}And here's the error message:
org.xml.sax.SAXParseException: Teckenkonverteringsfel: "Malformed UTF-8 char -- is an XML encoding declaration missing?" (radnumret kan vara f�r l�gt).
at org.apache.crimson.parser.InputEntity.fatal(InputEntity.java:1100)
at org.apache.crimson.parser.InputEntity.fillbuf(InputEntity.java:1072)
at org.apache.crimson.parser.InputEntity.isXmlDeclOrTextDeclPrefix(InputEntity.java:914)
at org.apache.crimson.parser.Parser2.maybeXmlDecl(Parser2.java:1183)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:653)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:185)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
at getrss.RSSDocument.<init>(RSSDocument.java:25)
at getrss.Main.main(Main.java:25)I read files from the web, but there is a XML tag
with the encoding attribute in the RSS file.If you are quite sure that you have an encoding attribute set to ISO-8859-1 then I expect that your RSS file has non-ISO-8859-1 character though I thought all bytes -128 to 127 were valid ISO-8859-1 characters!
Many years ago I had a problem with an XML file with invalid characters. I wrote a simple filter (using FilterInputStream) that made sure that all the byes it processed were ASCII. My problem turned out to be characters with value zero which the Microsoft XML parser failed to process. It put the parser in an infinite loop!
In the filter, as each byte is read you could write out the Hex value. That way you should be able to find the offending character(s). -
Psadmin list-dp : xml output is encoded with environment locale encoding
I am building some scripts to help me administer desktop profiles, providers jsp files, and others. Thoses scripts use the psadmin command.
I have hit what seems to me an unexpected behavior, when trying to download a desktop profile from a script :
the list-dp psadmin command output is encoded with the current environment locale encoding.
I suppose almost all psadmin commands localize and encode output as well, but in this case it is annoying : list-dp fails to output a valid xml file when xml header stated encoding (which is left untouched) and current locale encoding differ.
I have found a simple workaround which involve setting the environment locale to a fixed value, but I would like to know if this problem is known, and if it will be corrected (if it is not already) ?
My portal version is 7.0 with patch 121913-01,
the host system is SunOS 5.10 on a sparc host (v240).
Best RegardsWell, I have found the answer to my question :
The Sun Java System Portal Server 7.1 Release Notes bugs section refers to bug #6502307 and gives a workaround.
Here is the link to release note :
http://docs.sun.com/app/docs/doc/819-4986
and to bugs section :
http://docs.sun.com/app/docs/doc/819-4986/6n73o6vk6?a=view -
How to set encoding with xmldom ?
Hello !
I have to build an xml file from a query.
I need to have : <?xml version="1.0" encoding="ISO8859-1"?> on the first line.
I know how to set the version --> xmldom.setVersion(doc,'1.0'); ... but I don't know how to set the encoding.
Is there a way to set it ?
ThanksNo. It is not possible. Here is an extract of a document I found on metalink :
(XML Parser for PL/SQL FAQs)
Q: Is it possible to dynamically set the encoding in the XML document?
A: No, you must include the proper encoding declaration in your document, as
per the specification. You cannot use setCharset(DOMDocument) to set the
encoding for the input of your document. SetCharset(DOMDocument) is used
with oracle.xml.parser.v2.XMLDocument to set the correct encoding for
printing of the document. -
XML output with UTF8 Encoding scheme
In external partner wants that we provide him an XML file with data, encoded in UTF8 format.
Using the SQL/XML functions I can construct the XML with the structure (shcema) he asks for.
But how can I guarantee that my XML-output is in UTF8, because our oracle database has been built in the default character set WE8ISO8859PI.
I suppose it is not enough to add in front off my document: <?xml version="1.0" encoding="UTF8"?> ?Jan,
You may want to check on metalink for WE8iso8859P1 to see if it is a subset of UTF8. There are some documents on metalink that discuss the UTF8 character set and ways to pull differenct character sets and conversion from the database depending on what is stored in the database, or changing the database character set to UTF8.
Have you tried a test extract to see if the characters are correct? -
XML file with an attached MIME encoded ZIP file
Hi all,
I'm new to SAP WAS and MIME encoding/decoding, and I'm trying to generate an XML file with an attachment which is also MIME encoded.
1) I have dummy files (1.jpg, 2.jpg) and I'm trying to zip these files into one zip file (files.zip).
2) I'm trying to MIME encode/decode this zip file.
3) I'm trying to attach this MIME encoded zip file to existing XML file.
Which FMs could I use to accomplish this? Your help is very appreciated.
Thank you.
below is a file example that I'm trying to generate.
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="--XXXXboundary text"
Content-Transfer-Encoding: 7bit
This is a multi-part message in MIME format.
--XXXXboundary text
Content-Type: text/xml;
charset="utf-8"
Content-Transfer-Encoding: 8bit
<?xml version="1.0" encoding="utf-8"?>
<abc/>
<def/>
--XXXXboundary text
Content-Type: application/octet-stream; name="files.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
UEsDBBQAAAAIAI9EejAs5k34H84DAAYgBAAMAAAAMDAyMjQ5MTEucGRmnLsJWBNJ2zb6jmJIIIFE
BAMIJGEVBSKGRRAhEGQNoGwKYoiAEnYRUFGIkBAQFzYXRNHAAEGQZRy2ATFDUAHfGScSIUwQMMrM
ECGADptA0n/jzLtc//dd51znVAKdru6uqn7q6fu5764qQzJust create an applet (extend JApplet)... add a JTextArea to it....fill the text area with the text from an XML doc.
To get the text of the XML doc just do something like..
File xmlFile = new File("<path to xml file>");
FileInputStream fis = new FileInputStream(xmlFile);
byte[] bytes = new byte[(int) xmlFile.length()];
fis.read(bytes);
fis.close();
String xmlText = new String(xmlBytes);
textArea.setText(xmlText);
...try something like that (assuming..i understand what it is u want) -
Detection of encoding of XML file with the StAX parser
Hello!
I am using the StAX parser to read an XML file which can have different encodings.
I don't know how to detect the encoding before reading the file.
This is the way I instantiate the reader now:
XMLStreamReader xmlr = xmlif.createXMLStreamReader(new InputStreamReader (new FileInputStream(inputfile), "utf-8"));
Is there any way to make the reader detect the encoding with StAX? Is it possible detect the encoding with SAX or DOM?
Just paste some piece of code and you will help me a lot!
Thanks,
LaraXML parsers are supposed to auto-detect the encoding of their inputs. The SAX and DOM parsers built into Java, as well as others like Xerces, do that. I don't know whether your StAX parser does, but it should. There is a standard procedure for determining the encoding that is described in the XML spec.
However if you have malformed XML that fails to declare its encoding properly, then none of those parsers will be able to fix that problem for you.
Here's the simplified rule as it applies to most files: if the XML file doesn't have a prolog, or if it's prolog doesn't specify an encoding, the parser will assume the file's encoding is UTF-8. If the XML file does have a prolog that specifies an encoding, the parser will assume that encoding.
Unfortunately it is common for people to write XML files that don't declare an encoding, but to forget to encode the file in UTF-8. Then you have a file that is actually encoded in (e.g.) Windows-1252, but the parser believes it is UTF-8, and this fails when there are non-ASCII characters in the document. -
Inserting XML encoded ampersands into tables with OracleXMLSave / XMLLoader
Hi,
I've an XMLLoader application based on Steve Muench's design.
My client has given me XML documents with XML encoded ampersands.
The XMLloader (OracleXMLSave) is treating the ampersand as a substitution token and is adding chunks of unexpected text when it inserts the strings containing ampersands.
How do I turn off the substition within the JDBC?
Thanks,
Steve.If your XML Document looks like:
<ROWSET>
<ROW>
<FIELD1>val-1</FIELD1>
<FIELD12>val-12</FIELD12>
</ROW>
</ROWSET>
it will insert into just those two
fields, the rest will be null for
the purposes of the insert. -
Revision: 13383
Revision: 13383
Author: [email protected]
Date: 2010-01-08 12:04:00 -0800 (Fri, 08 Jan 2010)
Log Message:
Modify to include the xml header (with encoding) in the DITA xml files.
QE notes: None.
Doc notes: None
Reviewed By: Pete
Tests run: checkintests
Is noteworthy for integration: No
Modified Paths:
flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/asdoc/TopLevelClassesGenerator.ja vaThats good news.
-
Create xml file with values from context
Hi experts!
I am trying to implement a WD application that will have some input fields, the value of those input fields will be used to create an xml file with a certain format and then sent to a certain application.
Apart from this i want to read an xml file back from the application and then fill some other context nodes with values from the xml file.
Is there any standard used code to do this??
If not how can i do this???
Thanx in advance!!!
P.S. Points will be rewarded to all usefull answers.
Edited by: Armin Reichert on Jun 30, 2008 6:12 PM
Please stop this P.S. nonsense!Hi,
you need to create three util class for that:-
XMLHandler
XMLParser
XMLBuilder
for example in my XML two tag item will be there e.g. Title and Organizer,and from ur WebDynpro view you need to pass value for the XML tag.
And u need to call buildXML()function of builder class to generate XML, in that i have passed bean object to get the values of tags. you need to set the value in bean from the view ui context.
Code for XMLBuilder:-
Created on Apr 4, 2006
Author-Anish
This class is to created for having function for to build XML
and to get EncodedXML
and to get formated date
package com.idb.events.util;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.idb.events.Event;
public class XMLBuilder {
This attribute represents the XML version
private static final double VERSION_NUMBER = 1.0;
This attribute represents the encoding
private static final String ENCODING_TYPE = "UTF-16";
/*Begin of Function to buildXML
return: String
input: Event
public String buildXML(Event event) {
StringBuffer xmlBuilder = new StringBuffer("<?xml version=\"");
xmlBuilder.append(VERSION_NUMBER);
xmlBuilder.append("\" encoding=\"");
xmlBuilder.append(ENCODING_TYPE);
xmlBuilder.append("\" ?>");
xmlBuilder.append("<event>");
xmlBuilder.append(getEncodedXML(event.getTitle(), "title"));
xmlBuilder.append(getEncodedXML(event.getOrganizer(), "organizer"));
xmlBuilder.append("</event>");
return xmlBuilder.toString();
/End of Function to buildXML/
/*Begin of Function to get EncodedXML
return: String
input: String,String
public String getEncodedXML(String xmlString, String tag) {
StringBuffer begin = new StringBuffer("");
if ((tag != null) || (!tag.equalsIgnoreCase("null"))) {
begin.append("<").append(tag).append(">");
begin.append("<![CDATA[");
begin.append(xmlString).append("]]>").append("</").append(
tag).append(
">");
return begin.toString();
/End of Function to get EncodedXML/
/*Begin of Function to get formated date
return: String
input: Date
private final String formatDate(Date inputDateStr) {
String date;
try {
SimpleDateFormat simpleDateFormat =
new SimpleDateFormat("yyyy-MM-dd");
date = simpleDateFormat.format(inputDateStr);
} catch (Exception e) {
return "";
return date;
/End of Function to get formated date/
Code for XMLParser:-
Created on Apr 12, 2006
Author-Anish
This is a parser class
package com.idb.events.util;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import com.idb.events.Event;
import com.sap.tc.webdynpro.progmodel.api.IWDMessageManager;
public class XMLParser {
Enables namespace functionality in parser
private final boolean isNameSpaceAware = true;
Enables validation in parser
private final boolean isValidating = true;
The SAX parser used to parse the xml
private SAXParser parser;
The XML reader used by the SAX parser
private XMLReader reader;
This method creates the parser to parse the user details xml.
private void createParser()
throws SAXException, ParserConfigurationException {
// Create a JAXP SAXParserFactory and configure it
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
saxFactory.setNamespaceAware(isNameSpaceAware);
saxFactory.setValidating(isValidating);
// Create a JAXP SAXParser
parser = saxFactory.newSAXParser();
// Get the encapsulated SAX XMLReader
reader = parser.getXMLReader();
// Set the ErrorHandler
This method is used to collect the user details.
public Event getEvent(
String newsXML,
XMLHandler xmlHandler,
IWDMessageManager mgr)
throws SAXException, ParserConfigurationException, IOException {
//create the parser, if not already done
if (parser == null) {
this.createParser();
//set the parser handler to extract the
reader.setErrorHandler(xmlHandler);
reader.setContentHandler(xmlHandler);
InputSource source =
new InputSource(new ByteArrayInputStream(newsXML.getBytes()));
reader.parse(source);
//return the results of the parse
return xmlHandler.getEvent(mgr);
Code for XMLHandler:-
Created on Apr 12, 2006
Author-Anish
This is a parser class
package com.idb.events.util;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import com.idb.events.Event;
Created on Apr 12, 2006
Author-Anish
*This handler class is created to have constant value for variables and function for get events,
character values for bean variable,
parsing thr date ......etc
package com.idb.events.util;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import java.util.*;
import com.idb.events.Event;
import com.sap.tc.webdynpro.progmodel.api.IWDMessageManager;
public class XMLHandler extends DefaultHandler {
private static final String TITLE = "title";
private static final String ORGANIZER = "organizer";
IWDMessageManager manager;
private Event events;
private String tagName;
public void setManager(IWDMessageManager mgr) {
manager = mgr;
This function is created to get events
public Event getEvent(IWDMessageManager mgr) {
manager = mgr;
return this.events;
This function is created to get character for setting values through event's bean setter method
public void characters(char[] charArray, int startVal, int length)
throws SAXException {
String tagValue = new String(charArray, startVal, length);
if (TITLE.equals(this.tagName)) {
this.events.setTitle(tagValue);
if (ORGANIZER.equals(this.tagName)) {
String orgName = tagValue;
try {
orgName = getOrgName(orgName);
} catch (Exception ex) {
this.events.setOrganizer(orgName);
This function is created to parse boolean.
private final boolean parseBoolean(String inputBooleanStr) {
boolean b;
if (inputBooleanStr.equals("true")) {
b = true;
} else {
b = false;
return b;
This function is used to call the super constructor.
public void endElement(String uri, String localName, String qName)
throws SAXException {
super.endElement(uri, localName, qName);
/* (non-Javadoc)
@see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
This function is used to call the super constructor.
public void fatalError(SAXParseException e) throws SAXException {
super.fatalError(e);
This function is created to set the elements base on the tag name.
public void startElement(
String uri,
String localName,
String qName,
Attributes attributes)
throws SAXException {
this.tagName = localName;
if (ROOT.equals(tagName)) {
this.events = new Event();
public static void main(String a[]) {
String cntry = "Nigeria";
XMLHandler xml = new XMLHandler();
ArrayList engList = new ArrayList();
engList = xml.getCountries();
ArrayList arList = xml.getArabicCountries();
int engIndex = engList.indexOf(cntry);
System.out.println("engIndex :: " + engIndex);
String arCntryName = (String) arList.get(engIndex);
System.out.println(
">>>>>>>>>>>>>>>>>>>>" + xml.getArabicCountryName(cntry));
Hope that may help you.
If need any help , you are most welcome.
Regards,
Deepak -
Steps to UTF-8 Encoding with Oracle 8i and Weblogic 6.1SP1
What are the Steps to UTF-8 Encoding with Oracle 8i and Weblogic
6.1SP1?
I have:
- Oracle 8.1.5 database created with character set=UTF8 and national
character set=UTF8
- Weblogic 6.1SP1 without any encoding mechanism set
(though I did play with
<jsp-param><param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</jsp-param>
in the weblogic.xml for a while though it seemed not to make a
difference)
- JSP pages set to content='text/html; charset=UTF-8'
- JSP form POSTs set to enctype="UTF-8"
I can copy and paste Chinese Kanji from a UTF8 encoded web page into
form text boxes but when I post the data it comes back as different
Kanji. Then once it is posted the Kanji stays the same on repeated
posts. The same Kanji text also looks different when viewed in a form
text box than when viewed as straight text on the page.
Is there anything else? Or am I already encoding characters twice?
Please help!
Mel Christie
Hi Experts,
Please correct me if am asking you the question in wrong way.
I have ARCGIS with oracle database 10gr2 in production server.
My work is to connect AUTOCAD S/W (client computer which is connected in LAN) to ARCGIS in order to access the toposheets available in SDE user.
When iam trying to connect iam getting this error:The specified credentials are not valid or provider is not able to establish a connection.
I checked the path to production server by pinging and user/passcode too but not helpful.
Please help me in this , very urgent.
Thanks.
Edited by: user13355644 on Jul 3, 2010 3:53 AM
Edited by: user13355644 on Jul 22, 2011 2:55 AM -
IF_IXML : How can i add encoding with value UTF-8 to the document object??
Hi
i want to create a xml file with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://....">
</OpenSearchDescription>
i did this with the if_ixml interface and rendered the content in a file 'D:\usr\sap\IFD\DVEBMGS01\log\TEST_out.xml
<?xml version="1.0"?>
<OpenSearchDescription xmlns="http://....">
</OpenSearchDescription>
BUT the document attribut(?) encoding="UTF-8"?> is missing!
How can i add encoding with value UTF-8 to the document object?? it should look like:
<?xml version="1.0" encoding="UTF-8"?>
*here is my coding.
TYPE-POOLS: ixml.
CLASS cl_ixml DEFINITION LOAD.
DATA: lo_ixml TYPE REF TO if_ixml,
lo_streamfactory TYPE REF TO if_ixml_stream_factory,
lo_document TYPE REF TO if_ixml_document,
lo_parent TYPE REF TO if_ixml_element,
lo_ostream TYPE REF TO if_ixml_ostream,
lo_renderer TYPE REF TO if_ixml_renderer,
lv_rc TYPE i.
lo_ixml = cl_ixml=>create( ).
lo_streamfactory = lo_ixml->create_stream_factory( ).
lo_document = lo_ixml->create_document( ).
lo_parent = lo_document->create_simple_element( name = 'OpenSearchDescription' "root node
parent = lo_document ).
lo_parent->set_attribute_ns( name = 'xmlns'
value = 'http://....' ).
*rausrendern in file
lo_ostream = lo_streamfactory->create_ostream_uri( system_id = 'D:\usr\sap\IFD\DVEBMGS01\log\TEST_out.xml' ).
lo_renderer = lo_ixml->create_renderer( ostream = lo_ostream
document = lo_document ).
lv_rc = lo_renderer->render( ).
Thanks for help
BrittaUse the following code:
set an document encoding
l_encoding = l_ixml->create_encoding( character_set = 'UTF-8'
byte_order = if_ixml_encoding=>co_none ).
l_success = l_ostream->set_encoding( encoding = l_encoding ).
create a xml renderer
l_renderer = l_ixml->create_renderer( document = l_doc ostream = l_ostream ). -
HI all,
we try to post an XML message (cXML invoice) to a receiver but it doesn´t work.
We use a communication channel "http-destination" where we configure content-type "text/xml" together with XML encoding "UTF-8".
The configured URL works fine and can be tested in SM59.
The XML payload itself has a declaration <?xml version="1.0" encoding="UTF-8"?>
but the strange thing that happens is that all these declarations are being ignored and instead US-ASCII is used. Which leads to an error due to some special german characters within the contents of the XML (e.g. ä, ö, etc.).
Does anybody of you know how I can achieve that the pre-set UTF-8 will be used as encoding type???
Many thanky in advance!
Willi WuerstlinHi.
I am trying to map the standard cXML invoice to SAP's standard idoc INVOIC01 - This is how the file looks like
<?xml version="1.0" ?>
<!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.014/InvoiceDetail.dtd">
<cXML version="" payloadID="2008-07-29T04:51:08-06:00.cXML.TEST4101V002" timestamp="2008-07-29T04:51:08-06:00" xml:lang="en-US">
<Header>...</Header>
...</cxml>
I am having problem with the line <!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.014/InvoiceDetail.dtd"> - when the payload is having this line XI is not accepting the message.
Please let me know how to address this.
Thanks.
Maybe you are looking for
-
BIOS Sign-on message: MSI P965 Platinum A7238IMS V1.5B1 032207 (Date: 03/22/2007) Attachment name: A7238IMSv151.zip BIOS Sign-on message: MSI P965 Platinum A7238IMS V1.5B2 040407 (Date: 04/04/2007) Attachment name: A7238IMSv152.zip BIOS Sign-on messa
-
Transferring Plans from SOP to CO-PA
Dear Friends I am working on the integration of SOP and CO-PA, can you plz let me know the configuration relating to the transfer of SOP(Flexible planning) plans to CO-PA an Vice versa, if possible also the steps(transactions with codes) for transfer
-
Report Formula's effected by Query Prompt
We are developing a report in WEBI where the user enters Jan - Feb 2010. One of the colums on the report need to do a calculation using the 4 prior periods. Period Plan Actual *** Error (4 Prior) Jan 2010 100
-
Hello Friends, I have a doubt in creating job schedule. I created a stored proecedure for a particular process and i would like to execute that sp every 5 secs. i created a job scheduler and submitted that but could not able to run that. Can anyone t
-
Support for xs:date types in web services generated from EJB components
I need to generate a Web Service from an EJB session bean based upon EJB entities generated from the Oracle 11g database that contain DATE type columns. JDeveloper creates java.sql.Timestamp types in the EJB Session bean and this results in an except