Sax parse with offset
hi,
is there a way to start parsing xml file with sax using offest, the file i am parsing is over 2gb and its parsed on multiple machines, each machine parsing 1/n (number of machines) of the file, i managed to do this simply by counting starting element of a record and if criteria is met records are parsed, tho for the last part parser need to read whole file and when it gets to desired position it starts parsing, is there a way to do this using some kind of offset. total number of records is known.
tnx
hmhmmh, ok so here is the hole problem, this is all done and working properly, i just want to speed it up if possible.
in the beginning parsing was done on a single machine and since file is pretty big it took a lot of time, so we have made changes to code allowing it to be started from several machines and each one its doing one part of the same file (each instance has its copy), logic is: since number of records inside xml is known start and stop marker are calculated based on computer id and total number of computers on which parsing is done plus some safeties to ensure that every record is processed. so each instance of app knows when to start and stop parsing and simply goes through the file and counts number of records seen and when it reaches element representing start marker parsing is started and data sent where needed. parsing is done when sax reaches stop marker.
now i want to speed process of locating start marker since for the ie computer that is processing last part of the file app must go through entire file. i was asking if there is a way to tell sax where to "enter" the file so to say(ie 155th element, or in byte size, to simply move pointer to the xxxx byte)
and i need help on this matter since i have no idea how it can be done
Similar Messages
-
Trying to use XML SAX parser with JDK2 ...
Hi,
I'm pretty new to Java.
I'm trying to write and use java sample using XML SAX parser. I try with XP and XML4J.
Each time I compile it give me a error message like
"SAX01.java:23: unreported exception java.lang.Exception; must be caught or declared to be
thrown
(new SAX01()).countBooks();
^
Note: SAX01.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
1 error"
For what I found, it seems that "deprecated" mean usage of old classes or methods. What should I do ?
Wait for the XML parser to be rewrite ? ....
Thank's
Constant"SAX01.java:23: unreported exception
java.lang.Exception; must be caught or declared to be
thrown
(new SAX01()).countBooks();
^Do this
public static void main(String[] args) throws Exception {
or do this
try
first part of expression?(new SAX0()).countBooks();
catch(Exception ex)
System.out.println("problem "+ ex);
Note: SAX01.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
1 error"deprecation is just a warning if there are no errors elsewhere in your program it should compile fine, but if you want to find out how to change it do this:
javac YourClassName.java -deprecation
then look in the docs for an alternative. -
Is there a SAX parser with PL/SQL??
Hi All,
I am a Oracle developer and generally want to do everything from PL/SQL.
So, from a PL/SQL procedure I would like to parse a XML document. I have tried hard to find a PL/SQL package which can give me a PL/SQL SAX parser, but could not find one.
All packages are based on DOM tree.
Please convey if I am wrong and is there a SAX parser?
I know that there is only one package DBMS_XMLSTORE which is C based and uses SAX parser, but it does not have procedures/functions like ".parse()".
Thanks and regardsHere's an example
SQL> --
SQL> define MODULE=SaxProcessor
SQL> define CLASS=com/oracle/st/xmldb/pm/examples/SaxProcessor
SQL> --
SQL> set define off
SQL> --
SQL> var sourceFileName varchar2(32)
SQL> var targetPath varchar2(1024)
SQL> --
SQL> begin
2 :sourceFileName := 'JavaSource';
3 :targetPath := '/public/' || :sourceFileName || '.java';
4 end;
5 /
PL/SQL procedure successfully completed.
SQL> declare
2 res boolean;
3 javaSource clob :=
4 'package com.oracle.st.xmldb.pm.examples;
5
6
7 import java.io.IOException;
8 import java.io.StringWriter;
9
10 import java.io.Writer;
11
12 import java.sql.DriverManager;
13 import java.sql.SQLException;
14
15 import java.util.Enumeration;
16 import java.util.Hashtable;
17
18 import oracle.jdbc.OracleConnection;
19 import oracle.jdbc.OracleDriver;
20
21 import oracle.jdbc.OraclePreparedStatement;
22
23 import oracle.sql.BFILE;
24
25 import oracle.sql.CLOB;
26
27 import oracle.xml.parser.v2.SAXParser;
28 import oracle.xml.parser.v2.XMLDocument;
29 import oracle.xml.parser.v2.XMLElement;
30
31
32 import org.w3c.dom.Attr;
33 import org.w3c.dom.Element;
34 import org.w3c.dom.Node;
35
36 import org.xml.sax.Attributes;
37 import org.xml.sax.ContentHandler;
38 import org.xml.sax.Locator;
39 import org.xml.sax.SAXException;
40
41 public class SaxProcessor implements ContentHandler {
42
43 public static final boolean DEBUG = true;
44
45 private OracleConnection dbConnection;
46
47 private OraclePreparedStatement insertStatement;
48 private OraclePreparedStatement errorStatement;
49 private CLOB clob;
50
51 private Hashtable namespaceToPrefix = null;
52 private Hashtable prefixToNamespace = null;
53 private String targetElementName = null;
54
55 private XMLDocument currentDocument;
56 private Node currentNode;
57
58 private int documentCount = 0;
59
60 public SaxProcessor() {
61 this.namespaceToPrefix = new Hashtable();
62 this.prefixToNamespace = new Hashtable();
63 }
64
65 private boolean isTargetElement(String elementName) {
66 return ((this.currentDocument == null) &&
67 (elementName.equals(this.targetElementName)));
68 }
69
70 public void startDocument() throws SAXException {
71 }
72
73 public void endDocument() throws SAXException {
74 }
75
76 public void startElement(String namespaceURI, String localName, String elementName, Attributes attrs)
77 throws SAXException
78 {
79 if (DEBUG) {
80 System.out.println("startElement() : URI = " + namespaceURI + ", localName = " + localName + ", elementName = " + elementNa
me);
81 }
82 if (this.currentDocument == null)
83 {
84 if (DEBUG) {
85 System.out.println("startElement() : Checking for start of Fragment.");
86 }
87 if (isTargetElement(localName))
88 {
89 if (DEBUG) {
90 System.out.println("startElement() : Starting New Document");
91 }
92 this.currentDocument = new XMLDocument();
93 this.currentNode = this.currentDocument;
94 XMLElement rootElement = createNewElement(namespaceURI, localName, elementName, attrs);
95 this.currentDocument.appendChild(rootElement);
96 this.currentNode = rootElement;
97 }
98 }
99 else
100 {
101 XMLElement nextElement = createNewElement(namespaceURI, localName, elementName, attrs);
102 this.currentNode.appendChild(nextElement);
103 this.currentNode = nextElement;
104 }
105 }
106
107 public void endElement(String namespaceURI, String localName, String qName)
108 throws SAXException
109 {
110 if (this.currentDocument != null)
111 {
112 if (this.currentNode.equals(this.currentDocument.getDocumentElement()))
113 {
114 try
115 {
116 insertDocument();
117 this.currentDocument = null;
118 }
119 catch (SQLException sqlE)
120 {
121 throw new SAXException(sqlE);
122 }
123 catch (IOException ioe)
124 {
125 throw new SAXException(ioe);
126 }
127 }
128 else
129 {
130 this.currentNode = this.currentNode.getParentNode();
131 }
132 }
133 }
134
135 private XMLElement createNewElement(String namespaceURI, String localName,
136 String elementName, Attributes attrs) {
137 XMLElement newElement = null;
138 if (namespaceURI != null) {
139 if (this.namespaceToPrefix.containsKey(namespaceURI)) {
140 /* Namespace in already in Scope - create Element from Qualified Name */
141 newElement =
142 (XMLElement)this.currentDocument.createElement(elementName);
143 } else {
144 /* Namespace is not already in Scope - create Element with namespace */
145 newElement =
146 (XMLElement) this.currentDocument.createElementNS(namespaceURI,
147 elementName);
148 newElement.setPrefix((String)this.namespaceToPrefix.get(namespaceURI));
149 }
150 } else {
151 newElement =
152 (XMLElement)this.currentDocument.createElement(localName);
153 }
154 addAttributes(newElement, attrs);
155 if (this.currentNode.equals(this.currentDocument)) {
156 addNamespaceDeclarations(newElement);
157 }
158 return newElement;
159 }
160
161 private void addAttributes(Element element, Attributes attrs) {
162 for (int i = 0; i < attrs.getLength(); i++) {
163 if (attrs.getURI(i).equals("http://www.w3.org/2000/xmlns/")) {
164 } else {
165 element.setAttribute(attrs.getQName(i), attrs.getValue(i));
166 }
167 }
168 }
169
170 private void addNamespaceDeclarations(Element element) {
171 Enumeration keys = this.namespaceToPrefix.keys();
172 while (keys.hasMoreElements()) {
173 String namespace = (String)keys.nextElement();
174 String prefix = (String)namespaceToPrefix.get(namespace);
175 Attr attr = null;
176 if (prefix.equals("")) {
177 attr = this.currentDocument.createAttribute("xmlns");
178 attr.setValue(namespace);
179 element.setAttributeNode(attr);
180 } else {
181 if (!prefix.equals(element.getPrefix())) {
182 attr =
183 this.currentDocument.createAttribute("xmlns:" + prefix);
184 attr.setValue(namespace);
185 element.setAttributeNode(attr);
186 }
187 }
188 }
189 }
190
191 public void characters(char[] p0, int p1, int p2) throws SAXException {
192 if (this.currentDocument != null) {
193 StringWriter sw = new StringWriter();
194 sw.write(p0, p1, p2);
195 String value = sw.toString();
196 Node textNode = this.currentDocument.createTextNode(value);
197 this.currentNode.appendChild(textNode);
198 }
199 }
200
201 public void startPrefixMapping(String prefix,
202 String uri) throws SAXException {
203 this.namespaceToPrefix.put(uri, prefix);
204 this.prefixToNamespace.put(prefix, uri);
205 }
206
207 public void endPrefixMapping(String prefix) throws SAXException {
208 Enumeration e = prefixToNamespace.keys();
209 while (e.hasMoreElements()) {
210 String thisPrefix = (String)e.nextElement();
211 if (thisPrefix.equals(prefix)) {
212 String namespace =
213 (String)prefixToNamespace.remove(thisPrefix);
214 namespaceToPrefix.remove(namespace);
215 }
216 }
217 }
218
219 public void ignorableWhitespace(char[] p0, int p1,
220 int p2) throws SAXException {
221 // throw new SAXException ("Un-Implemented Method: ingnoreableWhitespace");
222 }
223
224 public void processingInstruction(String p0,
225 String p1) throws SAXException {
226 throw new SAXException("Un-Implemented Method: processingInstruction");
227 }
228
229 public void setDocumentLocator(Locator p0) {
230 // throw new SAXException ("Un-Implemented Method: setDocumentLocator");
231 }
232
233 public void skippedEntity(String p0) throws SAXException {
234 throw new SAXException("Un-Implemented Method: skippedEntity");
235 }
236
237 public void doParse(BFILE bfile, String targetElement,
238 String targetTable, String errorTable) throws Exception {
239 this.targetElementName = targetElement;
240 String insertStatementText =
241 "insert into " + targetTable + " values (xmlParse(DOCUMENT ? WELLFORMED))";
242 String errorStatementText =
243 "insert into " + errorTable + " values (xmlParse(DOCUMENT ? WELLFORMED))";
244
245 DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
246 OracleDriver ora = new OracleDriver();
247 this.dbConnection = (OracleConnection)ora.defaultConnection();
248
249 this.insertStatement =
250 (OraclePreparedStatement)this.dbConnection.prepareStatement(insertStatementText);
251 this.errorStatement =
252 (OraclePreparedStatement)this.dbConnection.prepareStatement(errorStatementText);
253
254 this.clob =
255 CLOB.createTemporary(this.dbConnection, true, CLOB.DURATION_SESSION);
256
257 SAXParser parser = new SAXParser();
258 parser.setAttribute(SAXParser.STANDALONE, Boolean.valueOf(true));
259 parser.setValidationMode(SAXParser.NONVALIDATING);
260 parser.setContentHandler(this);
261 bfile.openFile();
262 parser.parse(bfile.getBinaryStream());
263 bfile.closeFile();
264 this.insertStatement.close();
265 this.errorStatement.close();
266 }
267
268 private void insertDocument() throws SQLException, IOException {
269 this.clob.truncate(0);
270 Writer out = clob.setCharacterStream(0);
271 this.currentDocument.print(out);
272 out.close();
273
274 this.insertStatement.setClob(1, clob);
275 this.insertStatement.execute();
276
277 this.documentCount++;
278
279 if (DEBUG) {
280 System.out.println("insertDocument() : Document Inserted");
281 }
282 }
283
284 public static int parseBFile(BFILE bfile, String targetElement,
285 String targetTable, String errorTable) throws Exception {
286 try {
287 SaxProcessor processor = new SaxProcessor();
288 processor.doParse(bfile,targetElement,targetTable,errorTable);
289 return processor.documentCount;
290 }
291 catch (Exception e) {
292 e.printStackTrace(System.out);
293 throw e;
294 }
295
296 }
297 }
298 ';
299 begin
300 if dbms_xdb.existsResource(:targetPath) then
301 dbms_xdb.deleteResource(:targetPath);
302 end if;
303 res := dbms_xdb.createResource(:targetPath,javaSource);
304 end;
305 /
Queuing DELETE Event
PL/SQL procedure successfully completed.
SQL> --
SQL> set define on
SQL> --
SQL> create or replace and resolve java source
2 named "&MODULE"
3 using blob
4 (
5 select xdburiType('/public/JavaSource.java').getBlob(nls_charset_id('WE8ISO8859P1'))
6 from dual
7 )
8 /
old 2: named "&MODULE"
new 2: named "SaxProcessor"
Java created.
SQL> show errors
No errors.
SQL> --
SQL> declare
2 shortname varchar2(128);
3 begin
4 shortname := dbms_java.shortname('&CLASS');
5 execute immediate 'grant execute on "' || shortname || '" to public';
6 end;
7 /
old 4: shortname := dbms_java.shortname('&CLASS');
new 4: shortname := dbms_java.shortname('com/oracle/st/xmldb/pm/examples/SaxProcessor');
PL/SQL procedure successfully completed.
SQL> create or replace package SAX_PROCESSOR
2 as
3 procedure PARSE_BFILE(file BFILE, targetElement varchar2, targetTable varchar2, errorTable varchar2);
4 end;
5 /
Package created.
SQL> show errors
No errors.
SQL> --
SQL> create or replace package body SAX_PROCESSOR
2 as
3 --
4 procedure PARSE_BFILE(file BFILE, targetElement varchar2, targetTable varchar2, errorTable varchar2)
5 AS LANGUAGE JAVA
6 NAME 'com.oracle.st.xmldb.pm.examples.SaxProcessor.parseBFile( oracle.sql.BFILE, java.lang.String, java.lang.String, java.lang.Strin
g)';
7 end;
8 /
Package body created.
SQL> show errors
No errors.
SQL> --
SQL> drop table PO_TEST
2 /
Table dropped.
SQL> create table PO_TEST of XMLTYPE
2 /
Table created.
SQL> drop table PO_ERROR
2 /
Table dropped.
SQL> create table PO_ERROR of XMLTYPE
2 /
Table created.
SQL> create or replace directory xmldir as 'c:\temp'
2 /
Directory created.
SQL> set serveroutput on
SQL> --
SQL> call SAX_PROCESSOR.PARSE_BFILE(bfilename('XMLDIR','testcase.xml'),'PurchaseOrder','PO_TEST','PO_ERROR')
2 /
call SAX_PROCESSOR.PARSE_BFILE(bfilename('XMLDIR','testcase.xml'),'PurchaseOrder','PO_TEST','PO_ERROR')
ERROR at line 1:
ORA-29549: class XFILES.com/oracle/st/xmldb/pm/examples/SaxProcessor has
changed, Java session state cleared
SQL> call SAX_PROCESSOR.PARSE_BFILE(bfilename('XMLDIR','testcase.xml'),'PurchaseOrder','PO_TEST','PO_ERROR')
2 /
Call completed.
SQL> select count(*) from PO_TEST
2 /
3
SQL> select * from PO_TEST
2 /
<PurchaseOrder xsi:noNamespaceSchemaLocation="http://xfiles:8080/home/SCOTT/poSo
urce/xsd/purchaseOrder.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
">
<Reference>AMCEWEN-20030409123336271PDT</Reference>
<Actions>
<Action>
<User>KPARTNER</User>
</Action>
</Actions>
<Reject/>
<Requestor>Allan D. McEwen</Requestor>
<User>AMCEWEN</User>
<PurchaseOrder xsi:noNamespaceSchemaLocation="http://xfiles:8080/home/SCOTT/poSo
urce/xsd/purchaseOrder.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
">
<Reference>SKING-20030409123336321PDT</Reference>
<Actions>
<Action>
<User>SKING</User>
</Action>
</Actions>
<Reject/>
<Requestor>Steven A. King</Requestor>
<User>SKING</User>
<PurchaseOrder xsi:noNamespaceSchemaLocation="http://xfiles:8080/home/SCOTT/poSo
urce/xsd/purchaseOrder.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
">
<Reference>SMCCAIN-20030409120030451PDT</Reference>
<Actions>
<Action>
<User>SVOLLMAN</User>
</Action>
</Actions>
<Reject/>
<Requestor>Samuel B. McCain</Requestor>
<User>SMCCAIN</User>
SQL> -
Problem Using Sax parser with Eclipse 3.0 and command line
Hi,
I am parsing a xml file with sax. When I am running my programm in the command line everthing is ok and I get the right results from parsing.
But if I am running the programm in Eclipse 3.0 (the same java code) I get an other result (the wrong results).
Does anybody know what this can be the reason for. Is Eclipse using an other xml parser and if where I can change the parser?
It would be very kind if somebody can give me a reason for this strange behaviour.
Thanks in advanceI have solved my problem.
In the command line I used jre 1.4 and in Eclipse I used jre 1.5.
I think jre 1.5 uses an other xml parser so I got an other result.
If i use in Eclipse jre1.4 I get the same result as in the command line. -
How to stop the sax parser with parsing
hi,
I'm parsing some large xml-files with jaxp sax.
To do it I use a contenthandler that goes through the file.
Wat I want now is that when I have found the nodes that I need that parsing of the xml stops.
I tried to do it with detecting a certain endElement and putting there a return, but it will not work, parsing continues till the end of the file (see code underneath).
Does anyone can say what I'm doing wrong,
thanks, Hans
code:
public void endElement(String namespaceURI,
String sName,
String qName
) throws SAXException {
if (qName.equals("file")) {
return;
} // end of if ()
}You have to return from that method anyway, so a return statement is not going to tell the parser to stop. You could throw a SAXException, but be prepared to catch that in the code that called the parser, and be prepared to treat it differently from SAXExceptions that indicate problems.
-
Problem with SAX parser with String format
hi, all I have the next problem:
I try to parse xml file with success, I write next code:
====================
my_class saxUms = new my_class();
File file = new File( "c:\\my_try_Response.xml" );
InputSource src1 = new InputSource( new FileInputStream( file ) );
XMLReader rdr = XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser" ); rdr.setContentHandler( saxUms );
rdr.parse(src1);
===================
but when I try to parse the same in string variable, I write:
===================
my_class saxUms = new my_class();
StringReader strr = new StringReader(my_str);
InputSource intt = new InputSource(strr);
XMLReader prs= XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser" );
prs.setContentHandler(saxUms);
prs.parse(intt);
===================
and error occurs:
"Exception: java.lang.ClassCastException: java.lang.StringBuffer"
how to fix the problem?
Thank you for collaboration!where does the exception stack trace say the error is occurring?
-
SAX Parser Validation with Schemas (C, C++ and JAVA)
We are currently using the Oracle XML Parser for C to parse and validate XML data using the SAX parser interface with validation turned on. We currently define our XML with a DTD, but would like to switch to schemas. However, the Oracle XML Parser 9.2.0.3.0 (C) only validates against a DTD, not a schema when using the SAX interface. Are there plans to add schema validation as an option? If so, when would this be available? Also, the same limitation appears to be true for C++ and JAVA. When will any of these provide SAX parsing with schema validation?
Thanks!
JohnWill get back to you after checked with development team...
-
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? -
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.
-
XDK for C - SAX Parser Memory Problem
Hi,
I'm using the SAX Parser with custom Callbacks with XDK for C - version : Oracle XML Parser 9.2.0.6.0.
i'm parsing a single large XML file using the custom callbacks.
The issue i'm facing that the SAX Parser does not release any memory till complete parsing is over for the whole document(until xmlterm is called). This causes the parser to fail with LPX-00002 : OUT OF MEMORY error before the document parsing is complete.
I tried using custom memory callbacks but what i noticed is that the parser does not invoke the free Memory callback untill xmlterm is invoked.
If anybody has found an alternative to allow memory to be freed while SAX parsing is going on pls help me too.
Regards,
Vineet MagoCan you send the test case?
-
Hello..
I have the following problem. When I parse an xml document with blank spaces and numbers with decimals, its sometimes comes out as one string and sometimes as two, for example "First A" sometimes comes out as "First" and "A" and sometimes as "First A", which is how its stored in the xml file. Same with numbers like 19.20. Im enclosing a little of my code..
public void characters(char buf[], int offset, int len)
throws SAXException
if (textBuffer != null) {
SaveString = ""+textBuffer;
if(i>-1)
numbers = SaveString;
Whats wrong and how do I fix it.
Best Regards Dan
PS I have more code, in data and out data if needed.DsHello,
I do not know if this is your problem, yet please find hereafter an excerpt of the SAX API:
public void characters(char[] ch,
int start,
int length)
throws SAXException
... SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks;...
... Note that some parsers will report whitespace in element content using the ignorableWhitespace method rather than this one (validating parsers must do so)...
In other words, I am afraid that your issue is the "standard behaviour" of a SAX parser.
I hope it helps. -
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);
} -
Changing xmlschema while parsing with sax
Hello world,
I`m using the sax-parser (xerces) and i want to combine different schema-files to parse an xml-String;
<root>
<intervall>1,5</intervall>
<nix>jetzt echt nix!</nix>
<testtag>
<text>huhu joe</text>
</testtag>
<theLast>das letzte element</theLast>
</root>e.g. i want to parse the tag testtag with another schema ??
does anyone have an idea or a sample coding ??
thank you very muchthank you for the reply, but i want to change the Schema file while parsing the xmlString with Sax, without manipulation the xmlString;
the xml-String i get is fixed;
wish you all a great sunday -
I've a problem with errors message in the sax parser
Hello,
I'm quite new to Java.
I'm trying to create a SAX parser for my XML file, with a XML schema.
When my pars run a XML file, the following mistakes go out:
1)org.sax.SAXParseException:s4s-elt-must-match: the content of 'restriction' must match (annotation?,.....)
2)org.sax.SAXParseException: src-ct.0.1:Complex Type Definition Rappresentation Error for type..... Element 'sequence' is invalid,misplaced or occurs to often
but I don't understand where I must go in the schema to correct.
Many thanks!Hi,
Perhaps it would help if you post your XML file. -
OBIEE Writeback error Sax parser Expected entity name with ampersand gt/lt
Hi,
I've enabled OBIEE 10.1.3.3.2 on Suse Linux 9.x writeback successfully for an OBIEE report, however if any of the fields contain XML special characters like ampersand, less than, greater than symbols etc when I save I get error:
An error occurred while writing to the server. Please check to make sure you have entered appropriate values. If the problem persists, contact your system administrator.
Sax parser returned an exception. Message: Expected entity name for reference, Entity publicId: , Entity systemId: , Line number: 1, Column number: 795
Error Details
Error Codes: UH6MBRBC:E6MUPJPH
Xml parsed: <writeBack template="entry"><record action="update"><value columnID="c10">C</value><value columnID="c2">Jun-08</value><value columnID="c5">0001</value><value columnID="c1">NET RESULT</value><value columnID="c7">T000</value><value columnID="c3">Total X & X</value>...
I don't really want to have to use replace function on all the fields in the report to remove special characters + train users not to enter them in editable field.
Anyone got any ideas how to get around this?
Thanks,
GarethHi
I am getting this error in writeback while submitting
An error occurred while writing to the server. Please check to make sure you have entered appropriate values. If the problem persists, contact your system administrator.
Sax parser returned an exception. Message: Unterminated entity reference, 'M', Entity publicId: , Entity systemId: , Line number: 1, Column number: 85
Error Details
Error Codes: UH6MBRBC:E6MUPJPH
Xml parsed: <writeBack template="CPE_writeback"><record action="update"><value columnID="c0">H&M SWEDEN</value><value columnID="c1">7/5/2010</value><value columnID="c2">8/26/2010</value><value columnID="c11">Administrator</value><value columnID="c7">BOOKED</value><value columnID="c10"> y</value><value columnID="c9">H&M SWEDEN ;7/5/2010 ;8/26/2010 ;BOOKED</value></record></writeBack>
I think the problem is with '&' or might be with something else, if i choose other options form dropdowns its does not give me any error. only fot this customer "H&M SWEDEN"
can any one please tell me what workaround i can do.. the obi version is 10.1.3.2
Maybe you are looking for
-
SSO to J2EE application from SAP Portal
Hi I am trying to do SSO from SAP Portal to a J2EE engine which runs on SAP Web AS. Here are my queries 1. When I deploy a J2EE application on Web AS , I dont get any login screen. How can I make sure that if a user wants to access this J2EE applicat
-
How to install Adobe Flash Player in Iphone ?
how do i download Adobe Flash Player to my iphone ? i tried but it doesn't work. i understand it is needed to play Farmville & other Facebook games in iphone. pls help
-
Microsoft Exchange Server on Mac OS X Server
I am running Mac OS X Leopard Server on my Mac Pro with multiple clients, all using Mac OS X Leopard. Each client also has Microsoft Office 2008 for Mac installed with Entourage. Is it possible to install Microsoft Exchange Server on the Mac Pro and
-
Numbers can't open xls file by Windows Foxpro.
I have to open XLS files made by exporting a table in FoxPro using: EXPORT TO FileName XLS as mentioned in: http://msdn.microsoft.com/en-US/library/1515xf19(v=vs.80).aspx Whenever I try to open this file in Numbers I get the following error: I am usi
-
How do I remove sensitive data?
I want to make a hard copy of my security information, using Numbers and exit Numbers after printing. How can I be sure that none of my data remains on the machine? Would using a Guest account do this? What happens if Time Machine runs in the middle