naveena kamsali

Greenhorn
+ Follow
since Sep 20, 2011
Merit badge: grant badges
For More
India
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by naveena kamsali

hi friends,

can anyone tell about, how to call a method inside anonymous class which is created in a method.


naveena kamsali wrote:hi friends,

I have developed a simple sax program. But i didn't understand why we are writing DefaultHandler methods(startElement(),endElement() and characters()) in DefaultHandler block. Can anybody know about this. Please tell me.


package com.sax;

import java.io.IOException;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class Simple_sax{

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {

SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();

DefaultHandler handler = new DefaultHandler()


{
boolean bfname = false;
boolean blname = false;
boolean bnname = false;
boolean bsalary = false;

public void startElement(String uri, String localName,
String qName, Attributes attributes)
throws SAXException {

System.out.println("Start Element :" + qName);

if (qName.equalsIgnoreCase("FIRSTNAME")) {
bfname = true;
}

if (qName.equalsIgnoreCase("LASTNAME")) {
blname = true;
}

if (qName.equalsIgnoreCase("NICKNAME")) {
bnname = true;
}

if (qName.equalsIgnoreCase("SALARY")) {
bsalary = true;
}

}//startElement

public void endElement(String uri, String localName,
String qName)
throws SAXException {

System.out.println("End Element :" + qName);

}

public void characters(char ch[], int start, int length)
throws SAXException {

if (bfname) {
System.out.println("First Name : "
+ new String(ch, start, length));
bfname = false;
}

if (blname) {
System.out.println("Last Name : "
+ new String(ch, start, length));
blname = false;
}

if (bnname) {
System.out.println("Nick Name : "
+ new String(ch, start, length));
bnname = false;
}

if (bsalary) {
System.out.println("Salary : "
+ new String(ch, start, length));
bsalary = false;
}

}//characters


};
saxParser.parse("sax.xml",handler);


} catch (Exception e) {
e.printStackTrace();
}
}



}










thanks friends i got the answer...

Janki Shah wrote:How can I access inner class ten and it's integer variable x = 11 ?

CertPal Test






hi friend,


i have tried the pgm what you have posted here. i have cleared your problem. check the below program:




public class one
{
final Integer y=10;
two t=new two();
public class two//class inside class one
{

final int x;
public two() //constructor of class two
{
x = 10;

class ten //sub-class in class two
{
ten(){
int x = 11;
System.out.println("inside class ten"+x);
}
}
ten t=new ten();

System.out.println("inside class two"+x);
}
}
public int get() // method in class one
{
System.out.println("below two stmts output is class one inside get() method");
two two2 = new two();
return two2.x;

}
public static void main(String [] args)
{
one one = new one();
System.out.println("sum of two no.s is:"+(one.y + one.get()));

}
}
output is:

inside class ten11
inside class two10
below two stmts is of class one inside get() method
inside class ten11
inside class two10
sum of two no.s is:20
hi friends,

I have developed a simple sax program. But i didn't understand why we are writing DefaultHandler methods(startElement(),endElement() and characters()) in DefaultHandler block. Can anybody know about this. Please tell me.


package com.sax;

import java.io.IOException;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class Simple_sax{

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {

SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();

DefaultHandler handler = new DefaultHandler()


{
boolean bfname = false;
boolean blname = false;
boolean bnname = false;
boolean bsalary = false;

public void startElement(String uri, String localName,
String qName, Attributes attributes)
throws SAXException {

System.out.println("Start Element :" + qName);

if (qName.equalsIgnoreCase("FIRSTNAME")) {
bfname = true;
}

if (qName.equalsIgnoreCase("LASTNAME")) {
blname = true;
}

if (qName.equalsIgnoreCase("NICKNAME")) {
bnname = true;
}

if (qName.equalsIgnoreCase("SALARY")) {
bsalary = true;
}

}//startElement

public void endElement(String uri, String localName,
String qName)
throws SAXException {

System.out.println("End Element :" + qName);

}

public void characters(char ch[], int start, int length)
throws SAXException {

if (bfname) {
System.out.println("First Name : "
+ new String(ch, start, length));
bfname = false;
}

if (blname) {
System.out.println("Last Name : "
+ new String(ch, start, length));
blname = false;
}

if (bnname) {
System.out.println("Nick Name : "
+ new String(ch, start, length));
bnname = false;
}

if (bsalary) {
System.out.println("Salary : "
+ new String(ch, start, length));
bsalary = false;
}

}//characters


};
saxParser.parse("sax.xml",handler);


} catch (Exception e) {
e.printStackTrace();
}
}



}



Paul Clapham wrote:The useful information for you now is the stack trace which tells you what line of code threw the exception. Have a look at that, then have a look at the line of code which it points to.




Parser p=ParserFactory.makeParser("org.apache.xerces.parsers.SAXParser");
FindAllEmployees fae=new FindAllEmployees();
fae.eno=args[0]; //here i got the exception can you please tell me how to solve this
p.setDocumentHandler((DocumentHandler) fae);
hi,

try with a port no. 8081. this will work
11 years ago
hi friends,

I am learning SAX in xml. I am getting ArrayIndexOutOfBound Exception. can anybody know how to rectify this.

//this is the program which iam doing




//emp.xml file




//below is the dtd file