kiran

Greenhorn
+ Follow
since May 14, 2008
Merit badge: grant badges
For More
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
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by kiran

Hi all,

I got the solution finally.
It will take XML as input and will display the remaining content.

import java.io.BufferedReader;
//import java.io.File;
import java.io.FileNotFoundException;
//import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

//import com.thoughtworks.xstream.XStream;

public class ModifyXML
{

public static void main (String args[])
throws XmlPullParserException, IOException
{
StringBuffer sbfinal= new StringBuffer();
String myString=null;
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
StringBuffer buf = new StringBuffer();
try {
BufferedReader in = new BufferedReader(new FileReader("cache_response.xml"));
String line;
while ((line = in.readLine()) != null) {
buf.append(line + System.getProperty("line.separator"));
}
String yourXMLFileInAString = buf.toString();
xpp.setInput(new StringReader(yourXMLFileInAString));
System.out.println("---- >>>>> ");
boolean entered = false;

int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
System.out.println("Start document");
} else if(eventType == XmlPullParser.END_DOCUMENT) {
System.out.println("End document");
} else if(eventType == XmlPullParser.START_TAG) {
if(isSkip(xpp.getName()))
entered = true;
else if(!entered){
sbfinal.append("<"+xpp.getName()+">");
}
} else if(eventType == XmlPullParser.END_TAG) {
if(isSkip(xpp.getName()))
entered = false;
else if(!entered){
sbfinal.append("</"+xpp.getName()+">");
}
} else if(eventType == XmlPullParser.TEXT) {
if(!entered){
sbfinal.append(xpp.getText());
}
}
eventType = xpp.next();
}
myString = sbfinal.toString();
System.out.println(myString);
} catch (FileNotFoundException exp) {
exp.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}finally{
sbfinal=null;
myString=null;
}
}
public static boolean isSkip(String tagname){
if(tagname.equals("serviceBlock") || tagname.equals("statusBlock") || tagname.equals("____hashCodeCalc"))
return true;
else
return false;
}
}
Hi Guys,

I had an XML. I need to remove specified tags in XML, Need to display the remaining content by using XPP parser.
I have done by using DOM, Due to some performence issues, need to do by using XPP parser.

Please suggest me in this. Thanks in advance.