File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes problem with parsing xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "problem with parsing xml file " Watch "problem with parsing xml file " New topic

problem with parsing xml file

pvsr rao
Ranch Hand

Joined: Oct 05, 2005
Posts: 102
in web.xml file we have filter tag
in this i have to write programmitically

public void createFilter(String a,String b)
NodeList l = getRootNode().getChildNodes();
Node filterNode = l.item(2);as in web.xml second element is filter tag
String aa = "kk";
String bb = "kkk";
aa = a;
bb = b;
}catch(Exception e)

public void addFilter(Element filter,String a,String b)throws Exception
String name1="filterclass";
String name2="fill";
Element filtername=document.createElement("filter-name");
Element filterclass=document.createElement("filter-class");
Text spaceElement1 = document.createTextNode("\n");
Text spaceElement2 = document.createTextNode("\n");
Text spaceElement3 = document.createTextNode("\n");
Text spaceElement4 = document.createTextNode("\n");
Text filternameVal = document.createTextNode(name1);
Text filterclassVal = document.createTextNode(name2);
iam getting classcast exception.
please reply me what the wrong i have done.
if iam not casting to Element it is displaying error message as Node not allowed here
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Are you sure that "l.item(2)" returns an element? Maybe the index is off and it's returning something else?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Your comments suggest that you want to find the second element child of some node, but your code is actually finding the second node child instead. You forgot to take into account all those whitespace text nodes that are separating your tags.
I agree. Here's the link:
subject: problem with parsing xml file
It's not a secret anymore!