Sax parser support
hi,
i want to kow from which version jdk release sax parser is being supported.
regards
ac
XML APIs were added in Java 1.4.You could have saved you the time by checking the other threads. The question had already been answered, and that's why I just hate cross-posters.
/Kaj
Similar Messages
-
XML SAX parser that support LexicalHandler
Hello,
I'm looking for an XML SAX parser that support a LexicalHandler.
I have xml files that are not well formed, ie: (&, <, >, etc...) characters within tags and I need to ignore them.
Anyone have a link to some opensource library ??
Thanks,
SamirDon't waste your time. Using a LexicalHandler isn't going to help with parsing malformed XML. You should get the person who produced those files to replace them with correct XML.
PC² -
Why the SAX parser cannot support the special character like "¡"
I do not understand why the SAX parser cannot support the special character like ¡ but it can replace the " & < > to ", &, <, >, ,, but other characters will be replaced to empty charater.
can somebody give me any suggestions or solutions. THX.
Edited by: 844086 on 2011-3-14 上午2:27
Edited by: 844086 on 2011-3-14 上午2:27I quote:
Alternatively implement an EntityResolver that resolves the desired escapes.You are again an example that people only read/register the first thing written in a post. -
For a long time on technet the
PL/SQL parser release notes have
said that they will be supporting
SAX in a future release. Is there
any idea of when this support may
materialize? Or is Java the only
option for a parser in the db for
the near future that can handle large
documents?
nullWhat would you want to use as the implementation of the SAX2 ContentHandler interface in PL/SQL? Stored procedure-based callbacks? Just curious how you would envision this working. Your input is valuable to our future thinking in this area. Most teams using PL/SQL that want to use SAX have written Java Stored Procedures that use SAX internally inside the stored procedure (written in Java) but are not doing the SAX parsing with PL/SQL-based callbacks.
-
SAX Parser error when installing Oracle CCG 5.5.1
I am trying to install Oracle CCG on Windows 2008. I already have my PeopleSoft system installed on the same box, running weblogic and jdk1.7.0_03.
After setting the required environment variables, when I run the command "install.bat -f ccg-551-install.apf" from ccg_install folder, I get the following error:
Starting Oracle Installation Engine 1.2.1
Running from working directory C:\CCG\ccg_stage\
ORACLE_HOME is C:\app\Administrator\product\11.2.0\dbhome_1
JAVA_HOME is C:\Program Files\Java\jdk1.7.0_03
LAUNCH_CLASSPATH is C:\app\Administrator\product\11.2.0\dbhome_1\jdbc\lib\classe
s12.jar;C:\CCG\ccg_stage\install.jar;"C:\app\Administrator\product\11.2.0\dbhome
_1\lib";C:\Program Files\Java\jdk1.7.0_03\lib;C:\app\Administrator\product\11.2.
0\dbhome_1\lib;%CLASSPATH%
Oracle CCG Installer -- Version 1.2.1 Build(installer12-Maint-1.2.1.2)
Copyright 2009 Oracle. All rights reserved.
Initializing. Please wait...
FileParser: Parse error occurred: Could not load default SAX parser: org.apache.
xerces.parsers.SAXParser: SAX2 driver class org.apache.xerces.parsers.SAXParser
not found: org.apache.xerces.parsers.SAXParser
Could not load default SAX parser: org.apache.xerces.parsers.SAXParser: SAX2 dri
ver class org.apache.xerces.parsers.SAXParser not found: org.apache.xerces.parse
rs.SAXParser
I have tried downloading xerces.jar file and placed in the CLASSPATH folder but it did not help either. I do not have much knowledge about java and need help from someone who has installed CCG on windows.
Thank you in advanceSeveral things I would recommend here:
1. Use JDK 1.5 instead of 1.7, I'm pretty sure 1.7 isn't supported (Don't ask why) - [http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase5-419410.html|http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase5-419410.html]
2. Make sure to exit out all DOS command windows, then open a new one then go through setting all the environment variables, and using the same DOS command run the install command, otherwise all environment variables will be lost.
I hope that helps. -
Hi Team,
I am facing an issue while implementing a java mapping through SAX parsing.I am explaining it in details:
Source Structure
=================
MT_OB_SAX_MAP
>NUMBER1
>NUMBER2
Target Structure
==================
MT_IB_SAX_MAP
>ADD
>MUL
>SUB
The code that has been written to achieve this is:
//import java.io.FileInputStream;
//import java.io.FileOutputStream;
import com.sap.aii.mapping.api.StreamTransformation;
import java.io.*;
import java.util.Map;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
public class saxmapfinal1 extends DefaultHandler implements StreamTransformation
private Map map;
private OutputStream out;
private boolean input1 = false;
private boolean input2 = false;
private int number1;
private int number2;
private int addvalue;
private int mulvalue;
private int subvalue;
String lineEnd = System.getProperty("line.separator");
public void setParameter (Map param)
map = param;
public void execute (InputStream in, OutputStream out)
throws com.sap.aii.mapping.api.StreamTransformationException
DefaultHandler handler = this;
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
SAXParser saxParser = factory.newSAXParser();
this.out = out;
saxParser.parse(in, handler);
catch (Throwable t)
t.printStackTrace();
private void write (String s) throws SAXException{
try{
out.write(s.getBytes());
out.flush();
catch (IOException e){
throw new SAXException("I/O error", e);
public void startDocument () throws SAXException{
write("<?xml version=1.0 encoding=UTF-8?>");
write(lineEnd);
write("<ns0:MT_IB_SAX_MAP xmlns:ns0=urn:bp:xi:hr:edm:test:100>");
write(lineEnd);
public void endDocument () throws SAXException
write("</ns0:MT_IB_SAX_MAP>");
try { out.flush();
catch (IOException e) {
throw new SAXException("I/O error", e);
public void startElement (String namespaceURI, String sName, String qName,Attributes attrs)
throws SAXException {
String eName = sName;
if ("".equals(eName))
eName = qName;
if(eName.equals("NUMBER1"))
input1 = true;
if(eName.equals("NUMBER2"))
input2 = true;
public void endElement (String namespaceURI, String sName, String qName) throws SAXException {
String eName = sName;
if ("".equals(eName))
eName = qName;
if(eName.equals("NUMBER1"))
input1 = false;
if(eName.equals("NUMBER2"))
input2 = false;
public void characters(char[] chars,int startIndex, int endIndex) throws SAXException
String dataString =
new String(chars, startIndex, endIndex).trim();
if (input1) {
try
number1 = Integer.parseInt(dataString);
} catch(NumberFormatException nfe)
if (input2) {
number2 = Integer.parseInt(dataString);
if (input2 == true)
addvalue = number1 + number2;
mulvalue = number1 * number2;
subvalue = number1 - number2;
write("<ADD>" + addvalue +"</ADD>");
write(lineEnd);
write("<MUL>" + mulvalue +"</MUL>");
write(lineEnd);
write("<SUB>" + subvalue +"</SUB>");
write(lineEnd);
But while executing this in XI I am facing an error as "XML not well formed" but I am not able to know why this error is comming.
Can you please throw some light why this error is happening.?IWhat us the error in the code and what should be the correct code?
Many thanks for the support that I got in past.
Regards
Atanu Mazumdar
Edited by: ATANU1 on Apr 4, 2011 4:16 PMJust use characters() method for building string. Use endElement() to process that string.
-
Using xs:all element and the Weblogic provided SAX Parser
I am trying to validate XML documents against an xsd schema which has within it
the xs:all element to indicate that certain elements should be present but the
order in which they appear is not important. I have found that when I try to parse
a document against this schema using the SAXParser that is provided with Weblogic
the xs:all element seems not to be supported.
Has anybody else experienced this?
I have tried the same code but using a different SAX Parser (Apache provided)
and this no longer seems to be a problem.
Any advice would be appreciated.Hi Jonathan,
I took a quick look through our problem reports and did not see anything
related to this issue. Is this with WLS 8.1SP1? I'd suggest creating a
small reproducer and open a case with our award winning support group:
http://support.bea.com or [email protected]
Thanks,
Bruce
Jonathan Davison wrote:
>
I am trying to validate XML documents against an xsd schema which has within it
the xs:all element to indicate that certain elements should be present but the
order in which they appear is not important. I have found that when I try to parse
a document against this schema using the SAXParser that is provided with Weblogic
the xs:all element seems not to be supported.
Has anybody else experienced this?
I have tried the same code but using a different SAX Parser (Apache provided)
and this no longer seems to be a problem.
Any advice would be appreciated. -
RE: (forte-users) SAX Parser
I would be interested to see TechNote 11811. I just tried the Forté support
web site and couldn't get it. Can anyone help?
Thanks,
Nick.
-----Original Message-----
From: Zee Khan [mailto:[email protected]]
Sent: Tuesday, August 24, 1999 10:08 AM
To: [email protected]
Cc: [email protected]
Subject: RE: (forte-users) SAX Parser
Forte recommends not using DOM for 'documents with large
number of tags'
(TechNote 11811) so I am using SAX.
Any thoughts/suggestions would be welcome,
thanks,
>From: "Jeanne Hesler" <[email protected]>
>To: "'Zee Khan'" <[email protected]>,
<[email protected]>
>Subject: RE: (forte-users) SAX Parser
>Date: Tue, 24 Aug 1999 08:48:23 -0500
>
>Out of curiosity, is it the node structure that you are
trying to avoid,
>or is it the DOM itself? Can you share some of your
reasons? It would
>seem to me that a node or tree structure would be ideally
suited for
>representing the complex structures that you describe.
>
>Jeanne
>=====================================================
>Jeanne Hesler <[email protected]>
>MSF&W Software
>Product Development
>(217) 698-3535 ext. 207
>http://www.msfw.com
>=====================================================
>/\ Imaging Developer - the only imaging product
>\/ integrated into the Forte Development Environment
>=====================================================
>
>
>-----Original Message-----
>From: Zee Khan [mailto:[email protected]]
>Sent: Monday, August 23, 1999 10:32 AM
>To: [email protected]
>Subject: (forte-users) SAX Parser
>
>
>I am using the SAX parser to parse some complex XML.
>
>My problem comes with complex data structures. There
>are several embedded structures, how are these best
>reflected with a SAX parser.
>
>(I guess one solution is to use DOM which returns
>a node structure, but I want to avoid this)
>
>thanks in advace,
>
>
>______________________________________________________
>Get Your Private, Free Email at http://www.hotmail.com
>
>--
>For the archives, go to:
http://lists.sageit.com/forte-users
>To unsubscribe send in a new email the word:
>'Unsubscribe' to: [email protected]
>
>--
>For the archives, go to:
http://lists.sageit.com/forte-users and use
>the login: forte and the password: archive. To unsubscribe,
send in a new
>email the word: 'Unsubscribe' to:
[email protected]
>
Get Your Private, Free Email at http://www.hotmail.com
For the archives, go to: http://lists.sageit.com/forte-users
and use
the login: forte and the password: archive. To unsubscribe,
send in a new
email the word: 'Unsubscribe' to:
[email protected]I would be interested to see TechNote 11811. I just tried the Forté support
web site and couldn't get it. Can anyone help?
Thanks,
Nick.
-----Original Message-----
From: Zee Khan [mailto:[email protected]]
Sent: Tuesday, August 24, 1999 10:08 AM
To: [email protected]
Cc: [email protected]
Subject: RE: (forte-users) SAX Parser
Forte recommends not using DOM for 'documents with large
number of tags'
(TechNote 11811) so I am using SAX.
Any thoughts/suggestions would be welcome,
thanks,
>From: "Jeanne Hesler" <[email protected]>
>To: "'Zee Khan'" <[email protected]>,
<[email protected]>
>Subject: RE: (forte-users) SAX Parser
>Date: Tue, 24 Aug 1999 08:48:23 -0500
>
>Out of curiosity, is it the node structure that you are
trying to avoid,
>or is it the DOM itself? Can you share some of your
reasons? It would
>seem to me that a node or tree structure would be ideally
suited for
>representing the complex structures that you describe.
>
>Jeanne
>=====================================================
>Jeanne Hesler <[email protected]>
>MSF&W Software
>Product Development
>(217) 698-3535 ext. 207
>http://www.msfw.com
>=====================================================
>/\ Imaging Developer - the only imaging product
>\/ integrated into the Forte Development Environment
>=====================================================
>
>
>-----Original Message-----
>From: Zee Khan [mailto:[email protected]]
>Sent: Monday, August 23, 1999 10:32 AM
>To: [email protected]
>Subject: (forte-users) SAX Parser
>
>
>I am using the SAX parser to parse some complex XML.
>
>My problem comes with complex data structures. There
>are several embedded structures, how are these best
>reflected with a SAX parser.
>
>(I guess one solution is to use DOM which returns
>a node structure, but I want to avoid this)
>
>thanks in advace,
>
>
>______________________________________________________
>Get Your Private, Free Email at http://www.hotmail.com
>
>--
>For the archives, go to:
http://lists.sageit.com/forte-users
>To unsubscribe send in a new email the word:
>'Unsubscribe' to: [email protected]
>
>--
>For the archives, go to:
http://lists.sageit.com/forte-users and use
>the login: forte and the password: archive. To unsubscribe,
send in a new
>email the word: 'Unsubscribe' to:
[email protected]
>
Get Your Private, Free Email at http://www.hotmail.com
For the archives, go to: http://lists.sageit.com/forte-users
and use
the login: forte and the password: archive. To unsubscribe,
send in a new
email the word: 'Unsubscribe' to:
[email protected] -
Characters method in SAX parser
Hi
I have a SAX Parser Appln where in I am trying to run it in English Locale But the xml file contains Arabic Characters.
The method characters looks like this
public void characters(char buf[], int offset, int len) throws SAXException
if (recognisedTopElementStarted && storyStarted && recognisedElementStarted )
buffer.append ( new String(buf,offset,len) ) ;
//buffer.append ( new String(buf,offset,len,"UTF-16") ) ;
In this method I want to convert the char array to byte array so as to specify the encoding for constructing a String object(Arabic characters) with correct encoding as specified in the commented statement.
How to do it so as to get the arabic characters
Thanks
RajHi Raj,
I don't have Arabic support on my machine, so I tried with Greek, which has a significant Unicode code page.
To get a byte array, I did this:
byte[] ba = new String(buf, offset, len).getBytes("utf-16");To double check, I saved the byte array in a file output stream and validated the encoding in XML Spy.
So it works for Greek, let's hope it will work for our friends across the Mediterranean sea ;-)
Regards,
David -
tell me some disadvantages of the SAX parser.
Hi Sankar
Disadvantage of SAX are as follows
1)SAX is an event-driven push model for processing XML. It is not a W3C standard,
2)Rather than building a tree representation of an entire document as DOM does, a SAX parser fires off a series of events as it reads through the document.
3)The disadvantage of SAX is that you have to implement the event handlers to handle all incoming events. You must maintain this event state in your application code. Because the SAX parser does not communicate meta-information such as DOM's parent/child
4) you have to keep track of where the parser is in the document hierarchy. Thus, the more complex your documents are, the more complex your application logic becomes.
5)Even though there is no need to load the entire document into memory at one time, a SAX parser still needs to parse the whole document, as with DOM.
6)Probably the biggest problem facing SAX is that it does not have built-in document navigation support such as that provided by XPath. This, coupled with its one-pass parsing, means there is no random access support.
7)This limitation also shows up in namespaces: Elements that have inherited namespaces will not be annotated. These limitations make SAX a poor choice for manipulating or modifying a document
SAX (Simple API for XML) it is probably the most complete and accurate method so far.
This is used for XML documents.The SAX classes provide an interface between the input streams from which XML documents are read and the client software which receives the data made available by the parser. The parser browses through the whole document and fires events every time it recognizes an XML construct (e.g. it recognizes a start tag and fires an event the client software is notified and can use this information or not).
For more details you can refer to link
http://www.oracle.com/technology/oramag/oracle/03-sep/o53devxml.html
hope it may help you
Thanks
sandeep
PS: if helpful reward points -
How to deal with empty tags in a SAX Parser
Hi,
I hope someone can help me with the problem I am having!
Basically, I have written an xml-editor application. When an XML file is selected, I parse the file with a SAX parser and save the start and end locations of all the tags and character data. This enables me to display the xml file with the tags all nicely formatted with pretty colours. Truly it is a Joy To Behold. However, I have a problem with tags in this form:
<package name="boo"/>
because the SAX parser treats them like this:
<package name = boo>
</package>
for various complex reasons the latter is unaccetable so my question is: Is there some fiendishly clever method to detect tags of this type as they occur, so that I can treat them accordingly?
Thanks,
ChrisI have spent some time on googling for code doing this, but found nothing better, than I had to write in by myself.
So, it would be something like this. Enjoy :)
package comd;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;
import java.util.Stack;
import java.util.Enumeration;
public class EmptyTagsHandler extends DefaultHandler {
private StringBuilder xmlBuilder;
private Stack<XmlElement> elementStack;
private String processedXml;
private class XmlElement{
private String name;
private boolean isEmpty = true;
public XmlElement(String name) {
this.name = name;
public void setNotEmpty(){
isEmpty = false;
public EmptyTagsHandler(){
xmlBuilder = new StringBuilder();
elementStack = new Stack();
private String getElementXPath(){
StringBuilder builder = new StringBuilder();
for (Enumeration en=elementStack.elements();en.hasMoreElements();){
builder.append(en.nextElement());
builder.append("/");
return builder.toString();
public String getXml(){
return processedXml;
public void startDocument() throws SAXException {
xmlBuilder = new StringBuilder();
elementStack.clear();
processedXml = null;
public void endDocument() throws SAXException {
processedXml = xmlBuilder.toString();
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (!elementStack.empty()) {
XmlElement elem = elementStack.peek();
elem.setNotEmpty();
xmlBuilder.append("<");
xmlBuilder.append(qName);
for (int i=0; i<attributes.getLength();i++){
xmlBuilder.append(" ");
xmlBuilder.append(attributes.getQName(i));
xmlBuilder.append("=");
xmlBuilder.append(attributes.getValue(i));
xmlBuilder.append(">");
elementStack.push(new XmlElement(qName));
public void endElement(String uri, String localName, String qName) throws SAXException {
XmlElement elem = elementStack.peek();
if (elem.isEmpty) {
xmlBuilder.insert(xmlBuilder.length()-1, "/");
} else {
xmlBuilder.append("</");
xmlBuilder.append(qName);
xmlBuilder.append(">");
elementStack.pop();
public void characters(char ch[], int start, int length) throws SAXException {
if (!elementStack.empty()) {
XmlElement elem = elementStack.peek();
elem.setNotEmpty();
String str = new String(ch, start, length);
xmlBuilder.append(str);
public void ignorableWhitespace(char ch[], int start, int length) throws SAXException {
String str = new String(ch, start, length);
xmlBuilder.append(str);
} -
Hi,
I am parsing XML using SAX parser and fill the values into the HashTable ( like Key value pair ).. so i can get the vaues for a particular key using hash get function.
For the following XML. There are 2 "subscriberNumber" attribute, one is under "sn:Subscriber" and the another is under "sn:SubscriberChange".
I can able to put this values in hash table and when i print the Hash table it is printing as sn:subscriberNumber=[1234567890, 1234567890] .. But how will i know which one is from "sn:Subscriber" and which is from "sn:SubscriberChange"
This is the XML :
<sn:SubscriberNotification>
<sn:notificationSubType>1120</sn:notificationSubType>
<sn:Subscriber>
<cng:PaymentType>PostPaid</cng:PaymentType>
<sn:subscriberNumber>1234567890</sn:subscriberNumber>
</sn:Subscriber>
<sn:SubscriberChange>
<sn:subscriberNumber>1234567890</sn:subscriberNumber>
</sn:SubscriberChange>
</sn:SubscriberNotification>
Any suggestion and pointers are really helpful
Thanks,
-Raj..Try something like this:
import java.util.Stack;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
class MyHandler extends DefaultHandler {
Stack openTags = new Stack();
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (qName.equals("sn:subscriberNumber")) {
String parentTag = (String)openTags.peek();
System.out.println("Parent tag of this <sn:subscriberNumber> is : <" + parentTag + ">");
openTags.push(qName);
public void endElement(String uri, String localName, String qName) throws SAXException {
openTags.pop();
}Regards -
Hi all,
I am newbie to xml. I am using SAX parser for parsing xml documents. I have to write a code which parses all types of xsd files(including which can contain inline , referenced or both). Can anyone help / guide me how to code a generic xsd parser??
Thanks in advance,An XSD file is an XML file, so you can parse it using sax.
See :
http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/2a_echo.html
http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/work/Echo02.java
See also:
http://www.oracle.com/technology/tech/xml/xdk/doc/production/java/doc/java/javadoc/oracle/xml/parser/schema/XMLSchema.html#getXMLSchemaNodeTable -
Why are all the events in the XML SAX parser not activated?
Hi everyone,
I have written a mini server that parses XML files into SQL queries.
Below is a segment of my code;
try {
Class.forName( JDBC_DRIVER );
myConnection = DriverManager.getConnection( DATABASE_URL, "username", "password");
EventXMLParser myEXP = new EventXMLParser(directory, myConnection);
File[] xmlFiles = directory.listFiles();
for (File xmlFile : xmlFiles) {
myEXP.XMLtoDB(xmlFile);
outWriter.println("File:" + xmlFile.getName() + " DONE");
} catch (SQLException e) {
System.err.println("SQLException for establishing connection");
e.printStackTrace();
} catch (ClassNotFoundException e) {
System.err.println("CLASS NOT FOUND EXCEPTION HERE");
e.printStackTrace();
} catch (Exception e) {
System.err.println(e);
e.printStackTrace();
finally {
outWriter.println("PARSING COMPLETED");
outWriter.close();
}Where the constructor EventXMLParser constructs the following:
public EventXMLParser(File path, Connection connection) {
super();
try {
this.XMLpath = path;
this.db_connection = connection;
this.xr = XMLReaderFactory.createXMLReader();
this.XMLSAXhandler = new DefaultHandler(); //create a new own handler
this.xr.setContentHandler(XMLSAXhandler);
this.xr.setErrorHandler(XMLSAXhandler);
//System.out.println("DEBUG: db_connection is " + db_connection.toString());
catch (Exception e) {
System.out.println("Constructor Error!");
e.printStackTrace();
}Below are all my helper methods within EventXMLParser.java
public void XMLtoDB(String XMLpath) throws Exception {
try {
//Input
System.out.println("XMLpath is : " + XMLpath);
/*FileReader r = new FileReader(XMLpath); debug
InputSource in = new InputSource(r);
xr.parse(in);
xr.parse(XMLpath);
/* Note that while parsing, the end of each event, </event>
* will trigger sendSQL to execute the query on the database
catch (Exception e) {
throw new Exception("Error with XMLtoDB!! Exception: " + e);
public void sendSQL(Event event, Connection sql_connection) throws SQLException {
//JDBC part
try {
System.err.println("DEBUG sendSQL");
Statement sql_statement = sql_connection.createStatement();
ResultSet resultSet = sql_statement.executeQuery( event.toSQL() );
catch (SQLException e) {
e.printStackTrace();
/* Parsing XML
* From here onwards it's all designed for the SAX Parsing with different event calling methods
public void startDocument() {
System.err.println("Start Document");
public void endDocument() {
System.err.println("End Document");
public void startElement(String uri, String name, String qName, Attributes atts) {
CurrentElement= name;
System.out.println("This is parsing");
public void characters(char ch[], int start, int length) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
StringBuffer sb = new StringBuffer();
for (int i = start; i < start + length; i++)
sb.append(ch);
String content = sb.toString();
if (CurrentElement.equals("eid"))
temp.setEventID( (Integer.valueOf(content)).intValue() ) ;
else if (CurrentElement.equals("sd"))
temp.setShort_description(content);
else if (CurrentElement.equals("ld"))
temp.setLong_description(content);
else if ( (CurrentElement.equals("dt")))
temp.setDate_Time( formatter.parse(content, new ParsePosition(0)) );
else if (CurrentElement.equals("repeat"))
temp.setRepeat_pattern( (Integer.valueOf(content)).intValue() );
else if (CurrentElement.equals("valid"))
temp.setValid_period(content);
else if (CurrentElement.equals("status")) {
temp.setStatus( (Integer.valueOf(content)).intValue() );
else {}
public void endElement(String uri, String name, String qName) {
System.err.println("DEBUG" + temp.toString()); /*debug*/
if (name.equals("event")) {
try {
/*debug*/ temp.setUserID(1);
/*debug*/ System.err.println("DEBUG: " + temp.toString());
sendSQL(temp, db_connection);
//temp = new Event();
catch (SQLException e) {
System.err.println(e);
}//end catch
}//end try
Where event is a public class Event {
//fields
private int userID = 1; // = 1 only applies for testing
private int eventID;
private String short_description;
private String long_description;
private Date date_time = null;
private int repeat_pattern;
private String valid_period;
private int status; //1 for new, 0 for modification and -1 for delete
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//Constructors
//every event requires the following: userID eventID and short_Description
public Event(int uID, int eID, String shortDescrp) {
setUserID(uID);
setEventID(eID);
setShort_description(shortDescrp);
public Event(int uid, int eid, String sd,
String ld, Date d_t, int r_p, String v_p, int s) {
setUserID(uid);
setEventID(eid);
setShort_description(sd);
setLong_description(ld);
setDate_Time(d_t);
setRepeat_pattern(r_p);
setValid_period(v_p);
setStatus(s);
//set
public void setUserID (int x) { this.userID = x ;}
public void setEventID (int x) { this.eventID = x ;}
public void setShort_description (String x) { this.short_description = x ;}
public void setLong_description (String x) { this.long_description = x ;}
public void setDate_Time(Date x) { this.date_time = x ;}
public void setRepeat_pattern (int x) { this.repeat_pattern = x ;}
public void setValid_period (String x) { this.valid_period = x ;}
public void setStatus (int x) { this.status = x; }
//get
public int getUserID() { return this.userID;}
public int getEventID() { return this.eventID;}
public String getShort_description() { return this.short_description;}
public String getLong_description() { return this.long_description;}
public Date getDate_Time() { return this.date_time;}
public int getRepeat_pattern() { return this.repeat_pattern;}
public String getValid_period() { return this.valid_period;}
public int getStatus() { return this.status; }
//Event to SQL statements;
public String toSQL() {
StringBuffer sb = new StringBuffer();
///if ( status == 1) {
sb.append( "INSERT INTO events SET" );
sb.append( " userID = " + userID + ", ");
sb.append( "eventID = " + eventID + ", " );
sb.append( "short_description = " + "\'" + short_description + "\'" + ", "); //String
sb.append( "long_description = " + "\'" + long_description + "\'" + ", "); //String
sb.append( "date_time = " + "\'" + formatter.format(date_time) + "\'" + ", ");
sb.append( "repeat_pattern = " + repeat_pattern + ", " );
sb.append( "valid_period = " + "\'" + valid_period + "\'" ); //String
sb.append( ";");
//} else if ( status == 2) {
System.err.println(sb.toString());
return sb.toString();
} My question is: I have taken my SQL query generated by toSQL() method in events and it worked.
Here is the funny thing:
Everything is correct syntax wise: No complaints what soever
The mysql part works: Tested separately.
So I tend to think that the problem lies within the SAX parser. I have written SAX2 parsers on this machine before and they have worked too. I tried inserting println statements all over startElement endElement etc etc only to find out that the SAX parser did not call any of the methods that I overided!! Why is that so?
Can you guys spot where my SAX parser fails?I see.
I try to correct this problem by removing super();
so right now my code looks like this:
static Event temp = new Event(0, 0, "null", "null", new Date(), 0, "null", 0);
static String CurrentElement = null;
static File XMLpath;
static Connection db_connection;
static XMLReader xr;
static DefaultHandler XMLSAXhandler;
//Constructor, Build the SAX Parser
public EventXMLParser(File path, Connection connection) {
try {
this.XMLpath = path;
this.db_connection = connection;
this.xr = XMLReaderFactory.createXMLReader();
this.XMLSAXhandler = new DefaultHandler(); //create a new own handler
this.xr.setContentHandler(XMLSAXhandler);
this.xr.setErrorHandler(XMLSAXhandler);
//System.out.println("DEBUG: db_connection is " + db_connection.toString());
catch (Exception e) {
System.out.println("Constructor Error!");
e.printStackTrace();
}This time, I created a new instance of default handler() which can be referenced by as the objects's XMLSAXhandler. However, that did not solve the problem, why does the problem still persist?
Right now, there is only one instance of a default handler created. So why does all my parsing event functions still get ignored? -
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();
Maybe you are looking for
-
G/L Cleared document in back date which table i found?
I have posted a G/L Document on 01/02/2014 and cleared the same document on 10/03/2014. The g/l open Items are stored in BSIS Table and Cleared items are stored in BSAS Table. Now i want see the value in table level on 10/02/2014 (Back date) in which
-
Opening external pdf file from director
i'm a newby to director - is there an easy way to open an external pdf file from director. just need it to open in another window cheers s
-
Apex 4.2: migrating db tables between servers - methodology
Hello I'm just about to start migrating DB tables from apex.oracle.com onto our local server (by copying the CREATE statement from the Object Browser > SQL tab and then later exporting/importing data via Excel). Can anyone confirm that this is the be
-
TS1369 Iphone not being recognized
I keep getting the message that i have to update itunes. I keep trying but itunes says everything is up to date. meanwhile my phone does not appear in itunes
-
Hi! I received an IPHONE 4S as gift. It was bought it in China. When I started to use it, the ICON of you tube is missing. How can I recover it? Also, How can I change the language of google search in safari, because any search is showed in Chinesse.