473,769 Members | 6,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java SAX parser. How to get the raw XML code of the currently parsingevent

Java SAX parser, please need a clue how to get the raw XML code of the
currently parsing event... needed for logging, debugging purposes.

Here's and example, letting me clarify exactly what i need: (see the
comments in source)

public void startElement(St ring uri, String localName, String qName,
Attributes attributes) throws SAXException {
//..Here... or maybe somewhere elsewhere I need on my disposal the raw
XML code of every XML tags received from the XML stream.
//.. I need simply to write them down in a log file, for debugging
purposes, while parsing.
//.. Can anyone give me a suggestion how can i do that logging while
the SAX parser only returns me the tagname and attributes. While
parsing I want to log the XML code for every tag in its 'pure form',
like it is comming from the server directly on the socket's input
reader.

if ("p".equals(qNa me)) {
//Do
something...
}

}
Jul 2 '08 #1
5 7728
PatlaDJ wrote:
Java SAX parser, please need a clue how to get the raw XML code of the
currently parsing event... needed for logging, debugging purposes.

Here's and example, letting me clarify exactly what i need: (see the
comments in source)

public void startElement(St ring uri, String localName, String qName,
Attributes attributes) throws SAXException {
//..Here... or maybe somewhere elsewhere I need on my disposal the raw
XML code of every XML tags received from the XML stream.
I don't think the SAX API provides access to the raw XML.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 3 '08 #2
On 3 Þëè, 15:30, Martin Honnen <mahotr...@yaho o.dewrote:
PatlaDJ wrote:
Java SAX parser, please need a clue how to get the raw XML code of the
currently parsing event... needed for logging, debugging purposes.
Here's and example, letting me clarify exactly what i need: (see the
comments in source)
public void startElement(St ring uri, String localName, String qName,
Attributes attributes) throws SAXException {
//..Here... or maybe somewhere elsewhere I need on my disposal the raw
XML code of every XML tags received from the XML stream.

I don't think the SAX API provides access to the raw XML.

--

* * * * Martin Honnen
* * * *http://JavaScript.FAQTs.com/
Yes... now i'm pretty sure that it doesn't provide such access. Too
bad l;(

Right now i'm working towards clonning my input stream. Currently i'm
trying to clone the bufferedReader i pass as an inputsourse to the
parser ....i can't get it done :(

Let me explain: I read from a Socket ... the chain sequence is as
follows:

Socket -InputStreamRead er -BufferedReader -InputSource -then
it goes to .parse(InputSou rce)....of the SAX.

What node on this chain can be cloned so I can read the data two
times.....once for the parser, once for my debugging log.

Am I on the right track, or maybe not ?
Jul 3 '08 #3
Socket -InputStreamRead er -BufferedReader -InputSource -then
it goes to .parse(InputSou rce)....of the SAX.

What node on this chain can be cloned so I can read the data two
times.....once for the parser, once for my debugging log.
I'd suggest dealing with it at the Java level. Find or write a "wrapper"
reader implementation which saves a copy of the data passing through it
off to a data structure or scratch file for rereading, or perhaps which
writes the data direct to your log as it passes through. Plug that in
somewhere between the InputStreamRead er and the InputSource -- whether
upstream, downstream, or in place of the BufferedReader depends on the
details of how this tee adapter is written.
Jul 3 '08 #4
On 3 àÌÉ, 17:34, "Joseph J. Kesselman" <keshlam-nos...@comcast. net>
wrote:
Socket -InputStreamRead er -BufferedReader -InputSource -then
it goes to .parse(InputSou rce)....of the SAX.
What node on this chain can be cloned so I can read the data two
times.....once for the parser, once for my debugging log.

I'd suggest dealing with it at the Java level. Find or write a "wrapper"
reader implementation which saves a copy of the data passing through it
off to a data structure or scratch file for rereading, or perhaps which
writes the data direct to your log as it passes through. Plug that in
somewhere between the InputStreamRead er and the InputSource -- whether
upstream, downstream, or in place of the BufferedReader depends on the
details of how this tee adapter is written.
YES!

I've solved my problem using class RecordingInputS tream that wraps the
InputStream
here is the class source code:

import java.io.ByteArr ayOutputStream;
import java.io.FilterI nputStream;
import java.io.InputSt ream;
import java.io.IOExcep tion;

/**
*
* @author Unknown
*
*/

class RecordingInputS tream extends FilterInputStre am {
protected ByteArrayOutput Stream sink;

RecordingInputS tream(InputStre am in) {
this(in, new ByteArrayOutput Stream());
}

RecordingInputS tream(InputStre am in, ByteArrayOutput Stream sink)
{
super(in);
this.sink = sink;
}

public synchronized int read() throws IOException {
int i = in.read();
sink.write(i);
return i;
}

public synchronized int read(byte[] buf, int off, int len) throws
IOException {
int l = in.read(buf, off, len);
sink.write(buf, off, l);
return l;
}

public synchronized int read(byte[] buf) throws IOException {
return read(buf, 0, buf.length);
}

public synchronized long skip(long len) throws IOException {
long l = 0;
int i = 0;
byte[] buf = new byte[1024];
while (l < len) {
i = read(buf, 0, (int)Math.min(( long)buf.length , len -
l));
if (i == -1) break;
l += i;
}
return l;
}

byte[] getBytes() {
return sink.toByteArra y();
}

void resetSink() {
sink.reset();
}
}

Jul 3 '08 #5
SAX is a bit outdated... try either Pull or VTD-XML (http://vtd-xml.sf.net)

"PatlaDJ" <pa*****@gmail. comwrote in message
news:2a******** *************** ***********@a70 g2000hsh.google groups.com...
Java SAX parser, please need a clue how to get the raw XML code of the
currently parsing event... needed for logging, debugging purposes.

Here's and example, letting me clarify exactly what i need: (see the
comments in source)

public void startElement(St ring uri, String localName, String qName,
Attributes attributes) throws SAXException {
//..Here... or maybe somewhere elsewhere I need on my disposal the raw
XML code of every XML tags received from the XML stream.
//.. I need simply to write them down in a log file, for debugging
purposes, while parsing.
//.. Can anyone give me a suggestion how can i do that logging while
the SAX parser only returns me the tagname and attributes. While
parsing I want to log the XML code for every tag in its 'pure form',
like it is comming from the server directly on the socket's input
reader.

if ("p".equals(qNa me)) {
//Do
something...
}

}

Aug 4 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6918
by: ptaz | last post by:
Hi I'm trying to run a web page but I get the following error. Ca anyone please tell me a solution to this. Thanks Ptaz HTTP Status 500 - type Exception report
13
3346
by: Ajay | last post by:
hi! can you call a Python application from a Java program? does this require any additional package to be installed? thanks cheers
0
2682
by: Juan Manuel Fernández Luna | last post by:
Can anybody help me? I'm desperate!!! I'm writing a program in Java to deal with xml files and when the file volume.xml (attached) is being parsed, the following exception occurs and I don't what the problem is. Please, if you know why it happens or a site where I could ask, tell me. Best, Juanma
1
3109
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP Transformer convert that via XSLT to valid XSL-FO. So I define a SAXReader which fires the SAX Events for the Java Object. This works fine and the Transformation to PDF is ok. However, I have one object which contains an XHTML String and the tags
1
9651
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
2
6966
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
0
1136
by: Nageshwararao | last post by:
i getting path of XML file and parsing it. Following is error i am getting. can any one help me. Exception in thread "main" java.lang.InternalError com.sun.xml.parser.Parser.parseSystemId(Parser.java:2421) com.sun.xml.parser.Parser.maybeExternalID(Parser.java:2390) com.sun.xml.parser.Parser.maybeDoctypeDecl(Parser.java:1100)
318
11119
by: King Raz | last post by:
The shootout site has benchmarks comparing different languages. It includes C# Mono vs Java but not C# .NET vs Java. So I went through all the benchmark on the site ... http://kingrazi.blogspot.com/2008/05/shootout-c-net-vs-java-benchmarks.html Just to keep the post on topic for my friends at comp.lang.c++, how do I play default windows sounds with C++?
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.