jQuery in Action, 2nd edition*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "problem with parsing xml file " Watch "problem with parsing xml file " New topic
Author

problem with parsing xml file

pvsr rao
Ranch Hand

Joined: Oct 05, 2005
Posts: 102
in web.xml file we have filter tag
<filter>
<filter-name>filtername</filter-name>
<filter-class>filterclass</filter-class>
</filter>
in this i have to write programmitically

public void createFilter(String a,String b)
{
try
{
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;
addFilter((Element)filterNode,a,b);
}catch(Exception e)
{
e.printStackTrace();
}
}




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");
name1=a;
name2=b;
Text filternameVal = document.createTextNode(name1);
Text filterclassVal = document.createTextNode(name2);
filtername.appendChild(filternameVal);
filterclass.appendChild(filterclassVal);
filter.appendChild(filtername);
filter.appendChild(spaceElement4);
filter.appendChild(filterclass);
filter.appendChild(spaceElement3);
}
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
Marshal

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


Ping & DNS - my free Android networking tools app
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
 
wood burning stoves
 
subject: problem with parsing xml file
 
Similar Threads
xml problem
problem with accessiong method of another class
xml problem
Can anyone help?I still can't append records in xml...
problem with xml parsing