• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading log4j xml in java  RSS feed

 
jordan ryan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I am trying to read in my log4j.xml, edit some of the values then save it again. I am having some issues actually reading the xml because of the params etc.
Could anyone help me I know how to read a normal xml in with getNodeName and getElementsByTagName But this doesnt seem to work as the XML format is a bit more complicated.

this is my XML


This is the java code. It doesnt work atall, it isnt realising the tag name. When I put appender in it goes a step further but obviously thats not what I want. I want to be able to read it with the names I havew given.

 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is going to return an empty list because you don't have any elements named "file". I'm guessing you actually wanted to get the "appender" element which has a "name" attribute whose value is "file"? If that's the case then first find your "appender" elements and then look at their attributes to see if you have the right one.
 
jordan ryan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yer I kind of gather this and was having problems I now have the code I need, But I'm pretty sure I am over complecating it and not using best practise If I could get some help that would be great my issue is the current lines shouldn't really be there and instead of (1) it should find the one I'm looking for (the one which has text Content which equals file).

So thats the first bit in which I know can be changed but im a bit unsure how to do it, I'm then really doing to many ifs and else ifs and im pretty sure theres an easier way of doing this if anyone can help me or knows something I should look at in which will be an easier more efficient way please let me know.
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know... you didn't say whether that code did what you wanted or not. To me it has the normal amount of ugliness I'd associate with DOM manipulations, so if it does what it's supposed to do then I'd say it was fine.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jordan ryan wrote:Yer I kind of gather this and was having problems I now have the code I need, But I'm pretty sure I am over complecating it and not using best practise If I could get some help that would be great my issue is the current lines shouldn't really be there and instead of (1) it should find the one I'm looking for (the one which has text Content which equals file).

It sounds like you should be using XPath to find the specific element you want.
I suggest you look at the javax.xml.xpath package. There's also a java tutorial on XPath
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!