Edit an XML file with SAX
Dear all, I am so confused�.
I have been trying for the last few days to understand how sax works� The only thing I understood is:
DefaultHandler handler = new Echo01();
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
out = new OutputStreamWriter(System.out, "UTF8");
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(file , handler);
} catch (Throwable t) {
t.printStackTrace();
System.exit(0);
}Ok, I assign the SAXParser the xml file and a handler. The parser parses and throws events that the handler catches. By implementing some handler interface or overriding the methods of an existing handler (e.g DeafultHandler class) I get to do stuff�
But still, suppose I have implement startElement() method of DefaultHandler class and I know that the pointer is currently placed on an element e.g. <name>bob</name>. How do I get the value of the element, and if I manage to do that, how can I replace�bob� with �tom�?
I would really appreciate any help given� just don�t recommend http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/ because although there are interesting staff in there, it does not solve my problem�
Maybe SAX is not the right tool for you.
With SAX, you implement methods like startElement and characters that get called as XML data is encountered by the parser. If you want to catch it or not, the SAX parser does not care. In your case, the "bob" part will be passed in one or more calls to characters. To safely process the data, you need to do something like build a StringBuffer or StringBuilder in the constructor of the class, and then in the startElement, if the name is one you want to read, set the length to zero. In the characters method, append the data to the StringBuilder or StringBuffer. In the endElement, do a toString to keep the data wherever you want.
This works for simple XML, but may need to be enhanced if you have nested elements with string values that contain other elements.
On the other hand, if your file is not huge, you could use DOM. With DOM, (or with JDOM, and I would expect with Dom4J -- but I have only used the first two) you do a parse and get a Document object with the entire tree. That allows you to easily (at least it is easy once you figure out how to do it) find a node like the "name" element and change the Text object that is its child from a value of "bob" to "tom". With DOM, you can then serialize the modified Document tree and save it as an XML file. SAX does not have any way to save your data. That burden falls to you entirely.
Dave Patterson
Similar Messages
-
Reading xml file with sax parser: unknown protocol: c
Hi,
I've been googling around, and the best I can find is that the file name:
File test = new File("lib/test/parseTest/validate-test.xml");should be a url:
File test = new File("File://lib/test/parseTest/validate-test.xml");but I'm working on a linux machine and can't put "File://c:/pathToFile/file.xml"
Also, I did some testing and I can read a small xml file with just a few elements, but on large complex files, I get that error.
anyone ever run into this before?
bp
Edited by: badperson on Nov 1, 2008 2:19 PMbadperson wrote:
I've been googling around, and the best I can find is that the file name:
File test = new File("lib/test/parseTest/validate-test.xml");should be a url:
File test = new File("File://lib/test/parseTest/validate-test.xml");
No, that's wrong. The parameter for that constructor is a file path (relative or absolute). Not a URL. You must have misunderstood whatever you read.
but I'm working on a linux machine and can't put "File://c:/pathToFile/file.xml"What kind of a Linux machine is this which has a C drive? You must have misunderstood whoever told you to do that. -
How to Create XML file with SAX parser instead of DOM parser
HI ALL,
I am in need of creating an XML file by SAX parser ONLY. As far as my knowledge goes, we can use DOM for such purpose(by using createElement, creatAttribute ...). Can anyone tell me, is there any way to create an XML file using SAX Parser only. I mean, I just want to know whether SAX provides any sort of api for Creatign an element, attribute etc. I know that SAX is for event based parsing. But my requirement is to create an XML file from using only SAX parser.
Any help would be appreciated
Thanx in advance
KaushikHi,
You must write a XMLWriter class yourself, and that Class extends DefaultHandle ....., the overwrite the startElement(url, localName, qName, attributeList), startDocument(), endElement().....and so on.
in startElement write your own logic about how to create a new element and how to create a Attribute list
in startDocument write your own logic about how to build a document and encodeType, dtd....
By using:
XMLWriter out = new XMLWriter()
out.startDocument();
Attribute attr1 = new Atribute();
attr1.add("name", "value");
out.startElement("","","Element1", attr1);
Attribute attr2 = new Atribute();
attr2.add("name", "value");
out.startElement("","","Element2", attr2);
out.endElement("","","Element2");
out.endElement("","","Element1");
out.endDocument(); -
Editing a XML file with PHP and HTML or AS2
Hi webmates...
I have been looking for a good tutorial on managing an XML
file through Flash (AS2) or HTML and PHP... but all of what I have
found at the moment are very confusing and incomplete... the
examples actually do not work ok...
Would anyone mind on addressing me any good place where I can
find nice tutorials for this ? perhaps any example ? I wil really
appreciate it, My web is already reading the XML file to load
data... but I also need to create an application for editing this
XML... thanx in advance...I have no experience with any decompilers beyond possibly attempting to trial one once. The only one I have seen recommended is made by Sothink.
Here is a link to a page with a tool that has an interface you can use to determine various properties of an swf file, including the Actionscript version.
http://blog.sitedaniel.com/2009/11/swf-info-width-height-swf-version-actionscript-version- framerate/ -
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 -
Can no longer edit app descriptor file with 3.4 - really?
Until now, when publishing to AIR from Flash Professional, I could manually edit the app descriptor XML with a little workaround:
1. Set up my publish settings in Flash Professional and click OK
2. Then edit the XML file and save it
3. Then Publish from Flash Professional WITHOUT opening the Publish Settings again (which would recreate the XML file).
This has been CRUCIAL to me in order to add certain elements to the XML file such as <extensions> I want to include with my project.
However, this seems impossible to do with the 3.4 AIR SDK release version. When I try, it ignores my manual edits of the XML file and simply removes them when I publish. This is a HUGE problem because now I can no longer add <extensions> in the app descriptor file (and this can't be done from the Flash Professional GUI).
Anyone have ANY idea how to keep adding my extensions to the app descriptor file?Hello,
I have the same problem, but not the same solution : I have an old air application under Air 2.0, with an automatic updater, and wanted to make an intermediate application as seen here : http://helpx.adobe.com/air/kb/update-air-2-or-earlier.html .
So I have to change the application descriptor by hand. But Flash CS6 always overwrite this descriptor with its own datas while exporting.
How can I change my application descriptor for this intermediate version ? I have Flash CS5, but not Flash CS5.5, and the extension for Flash CS5 doesn't exist anymore !
Thanks ! -
Create XML file with worksheet's dynamically assigned through XSLT
Hi all
I have a requirement to create a xml file with worksheets dynamically created based on a field value in the internal table .
I have all my values in internal table, and am calling the transformation from bsp application.
Say the internal table has field dataxyz, for every change in value in this field dataxyz i need to create separate worksheet and populate that sheet with some corresponding values .
please guide me how to create worksheet dynamically.
thanks in advance.
Bharathy
Edited by: elam.bharathy on May 16, 2011 6:51 AMCan you use a schema when we compose XML doc from Database tables?
Actually, I'm using SQL Server (sorry, wrong forum). But, I thought a Java tool would have a solution for me. -
Transfer 100M XML file with XSL
Hi,
I am trying to transfer 100M XML file with XSL. Input.xml is the XML file, format.xsl is the XSL file. I type in the command line as:
java org.apache.xalan.xslt.Process -IN input.xml -XSL format.xsl -OUT output.xml
It got "out of memeory" error. My questions are:
1. Is it possible to transfer such large XML file with XSLT?
2. The XSL processor used SAX or DOM to parse XML file?
3. Any suggestions?
Thanks.
Jamesmaybe?
java -Xmx200m org.apache.xalan.xslt.Process -IN input.xml -XSL format.xsl -OUT output.xml
http://java.sun.com/j2se/1.3/docs/tooldocs/win32/java-classic.html -
How do you display xml file with xlst sheet in jsp
I have an xml file with accompanying xslt file (and several images that are used in a single directory. If I doubleclick on the xml file, it displays perfectly in my browser - Formatting, images and all!
The 100 dollar question - How do I duplicate this behavior in a JSP page in WebLogic 8.1 using the code in the xml and the accompanying xslt (formatting) file? I tried simple embedding the xml code in the jsp, but that didn't seem to work. What is the secret?
Okay, I need to add a bit more information here. I understand that it is really easy to just redirect to the XML file. The issue is really security. I want the XML to be inside a jsp that will only allow validated users to view it.
Another way to look at the problem would be, can I add a jsp security tag to the xml file? Or how to I add the xml code inside a jsp and keep the path references to the xslt and graphics.
Hope the added information helps
Thanks,
Ken
Message was edited by: KLee - 20050609 10:25 MST
[email protected]This proved out to be the answer. Thanks for the direction!
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class XML_XSLT_Servlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
String xmlfile = req.getParameter("xmlfile"); if (xmlfile==null) xmlfile = "test.xml";
String xsltfile = req.getParameter("xsltfile"); if (xsltfile==null) xsltfile = "test.xslt";
/* Test if file exists!, or use default file */
File f1 = new File(getServletContext().getRealPath("WEB-INF/displayfiles/"), xmlfile);
File f2 = new File(getServletContext().getRealPath("WEB-INF/displayfiles/"), xsltfile);
if (f1.exists() && f2.exists()) {
// System.out.println("Files Found");
} else {
System.out.println("XML and XSLT Files NOT Found");
System.out.println(f1.getPath());
System.out.println(f1.getName());
xmlfile = "test.xml";
xsltfile = "test.xslt";
InputStream fileXML = getServletContext().getResourceAsStream("WEB-INF/displayfiles/" + xmlfile);
InputStream fileXSLT = getServletContext().getResourceAsStream("WEB-INF/displayfiles/" + xsltfile);
OutputStream os = res.getOutputStream();
TransformerFactory xFactory = TransformerFactory.newInstance();
StreamSource stylesheet = new StreamSource(fileXSLT);
Transformer xformer = null;
try {
xformer = xFactory.newTransformer(stylesheet);
} catch (TransformerConfigurationException tfce) {
tfce.printStackTrace();
StreamSource input = new StreamSource(fileXML);
StreamResult output = null;
try {
output = new StreamResult(os);
} catch (Exception e) {
e.printStackTrace();
try {
xformer.transform(input, output);
} catch (TransformerException xfe) {
xfe.printStackTrace();
<pre></pre><pre></pre> -
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). -
Buiding xml file using SAX parser of JAXP
Please send me xml building using the sax parser.This is the urgent requirement ,iam not geeting how to solve this problem.so please anybody can help with one best example
You don't build an XML file with a parser. A parser reads an XML file and converts it to some internal representation. Try reading this tutorial:
http://java.sun.com/xml/jaxp/dist/1.1/docs/tutorial/ -
Editing an XML FIle TextEdit?
How can I edit an XML file?
When I open an XML file in TextEdit, all the tags get stripped out?
When I double click on my XML files, "Dashcode" starts up but always hangs, making it useless for this purpose (whatever it is).When I open an XML file in TextEdit, all the tags get stripped out?
This a bit odd: I tried opening an xml file in TextEdit with the default for a new document set to either plain or rich text, and with 'ignore HTML commands' and 'ignore Rich Text' commands' checked or unchecked and was always able to open it showing the tags, either by dragging it to the icon or using the File>Open method. It even worked if I removed the .xml extension (and even with the .txt extension). How are you opening it?
On the off-chance that there is something odd about your file, download the xml file I was testing from this link:
https://files.me.com/rfwilmut/kdmnuu
(it's zipped) and see if you can open that. -
Open XML file with user default browser and not the default editor.
Hi,
I'm writing a java program that appends numerous XML files together. The result is a NEW well formed XML document. Since i have an XSLT that performs several UI modifications on this xml file, the file extension must remain '.xml'. I need to open this xml file with the users default web browser. The problem is that:
Runtime.getRuntime().exec(cmd);
....opens the xml file with the users default program for opening xml files which in my case is Oxygen. I want to force java to open this xml file with the users default web browser and nothing else.
I guess i need the Windows command to perform the 'open with' feature but i have no idea what that command is or how to find it.
Any ideas?
Thanks,
Varun Singh
Edited by: Jagara00 on Jul 2, 2009 3:49 PMsabre150 wrote:
Jagara00 wrote:
Your right, but my question relates to the java issue and not the XSLT aspect of the problem. I am looking for a java solution for reasons i will no go into here. You have lost me.Me too.
People do not often ask questions (or make challenges or observations) idly for the sake of 'theory'. It is most useful to explain to the best of your ability.
As to
"Since the Desktop class was only released with SE 6 I am forced to find another alternative. "
There is an 'alternative'. You can import it into a 1.5 project. It was available as a free standing API before 1.6 - through JDIC. See [https://jdic.dev.java.net/documentation/Examples.html|https://jdic.dev.java.net/documentation/Examples.html] for more info.
Edit 1:
To a later reply
"Do u .."
..want to spell incorrectly when you get frustrated?
"..do not wish to.."
..get any help? That is the way you are heading.
Edited by: AndrewThompson64 on Jul 3, 2009 9:27 AM -
Parsing XML file with different languages (Xerces)
How do we code or program to an XML file with different
languages , say english and spanish. WHen we parse such a document with the default locale , the presence of special characters throws errors .For eg when I use xerces and use
DOMParser parser = new DOMParser();
try
// Parse the XML Document
parser.parse(xmlFile);
catch (SAXException se)
se.printStackTrace();
org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0xfc) was found in the element content of the document.
System Error: void org.apache.xerces.framework.XMLParser.parse(org.xml.sax.InputSource)
So what locale do we set before we parse ?How to handle this problemYou need an encoding attribute in the xml declaration. If you don't, the parser assumes UTF-8, which are ASCII characters up to 127 - useful (only) for English.
So, something like this would allow you to use characters above 127, ISO-8859-1 is the encoding used by standard PCs.
<?xml version="1.0" encoding="ISO-8859-1"?>
You can find a (offical) list of encodings at:
http://www.iana.org/assignments/character-sets
I'm not sure about mixing various encodings. I think you have to resort external parsed entities, which can have their own encoding, but I think you cannot mix encodings in one XML file.
Good luck. -
XML file with different format
Hello
I have a requirement where the customer needs XML file with different format. How do I achieve the second format mentioned below instead of first format.
Normally we create the XML file in the following format:
- <Entries>
- <Organization>
<MemberName>0000000002</MemberName>
<FullName>BAY GYNECOLOGICAL ASSOCIATES</FullName>
<OrgId>0000000002</OrgId>
<OrgType>CUST</OrgType>
- <AssociatedToOrg>
<Name>0002</Name>
- </AssociatedToOrg>
</Organization>
Now the customer wants like the following format:
<Organization MemberName="522_Community_Customer" FullName="522 Community Customer" OrgId="DEA123456" OrgIdType="DEA" >
<AssociatedToOrg Name="MN"/>
</Organization>
Thanks
Nagayou can solve it with a XSL mapping. refer to the SDN to know how develop it
/people/aleksey.popov2/blog/2010/01/26/consuming-webservices-with-tag-in-wsdl-using-xslt
XSLT Editor for creating xlst mappings
http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/190eb190-0201-0010-0ab3-e69f70b6c257
http://wiki.sdn.sap.com/wiki/display/XI/XSLTMappingSteps
http://wiki.sdn.sap.com/wiki/display/XI/FileTOFile-UsingXSLTmapping%28forBeginners%29
http://wiki.sdn.sap.com/wiki/display/Snippets/ConvertflatXMLfiletonestedusing+XSLT
http://wiki.sdn.sap.com/wiki/display/Java/MultiMappingwithJavaandXSLTmappings
Edited by: Rodrigo Alejandro Pertierra on Oct 1, 2010 5:26 PM
Maybe you are looking for
-
So I just got a new laptop, I downloaded iTunes I Authorized the computer and all that, I transported my purchases from my account and all went well, But I just want to know if it's possible to take the music from my iPod Touch 4 and put in on the la
-
when it starts, it's normal color like before. But After the booting, the color of monitor changed. No Grey color. it looks like posterized. I checked all setting of display but It's ok. I heard that's not hardware problem because when it started, it
-
Auto recovery and why is it happening?????
As I am working in excel or word, could be other programs, I notice a quick flash at the bottom of the excel sheet say " auto recovery". It seems to save what I am working on because you can't "undo" what you were working on once it flashes " auto re
-
Standby Problem - 42inch AV55*D -
Simply wont switch on - get red light, wont turn on, a weak green light flashes momentarily, but from digging it seems this a common issue with Toshibas and can be fixed by a TV repairman? Any other info?
-
After downloading updates for apps to PC they are not syncing over to phone.
Hi, I have noticed today that if I download app updates to my PC for my iphone 4 or ipad 3, they are not updating on the devices when syncing. Running latest iOS on devices and using Itunes 11.0.1.12 Have seen on the app page on PC, you can select e