This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with parsing xml file  RSS feed

pvsr rao
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that "l.item(2)" returns an element? Maybe the index is off and it's returning something else?
Paul Clapham
Posts: 22185
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!