This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Reading log4j xml in java  RSS feed

 
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.

 
Marshal
Posts: 24492
55
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
Marshal
Posts: 24492
55
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.
 
Bartender
Posts: 3323
86
  • 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
 
Yes, my master! Here is the tiny ad you asked for:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!