0

I get XML file on server "localhost:7878" as shown in image. I have to read tag values from there. Highlighted part changes every second. Currently I'm parsing XML file and reading it. Is there any better way where I directly get tag values? enter image description here

Nikhil Chilwant
  • 629
  • 3
  • 11
  • 31
  • If the server only gives you that XML file, you have no option but to parse it. Are you using DOM or SAX? – Kayaman Apr 04 '14 at 12:51
  • currently I'm using DOM. Is there any better way? – Nikhil Chilwant Apr 04 '14 at 12:54
  • If you're only interested in those specific parts, SAX would be a more obvious choice. It wouldn't make a significant difference, but it would still be faster and more memory efficient. – Kayaman Apr 04 '14 at 12:57
  • Will it be able to 'listen' changes in tag values? – Nikhil Chilwant Apr 04 '14 at 12:59
  • No, since the server doesn't have a way of notifying you (I assume), you can only poll the server for changes. This applies to every choice you have, whether you use SAX, JAXB, DOM, StaX or any other technology. If the server doesn't want you to know about the changes, then you won't know. – Kayaman Apr 04 '14 at 13:02
  • Suppose server has a way to notify? what are options for notifying? – Nikhil Chilwant Apr 04 '14 at 13:03
  • Does the server have a way? Are you responsible for the server code? – Kayaman Apr 04 '14 at 13:04
  • no. Not exactly. Some other program is writing on this server in standard XML format. We are just reading it. – Nikhil Chilwant Apr 04 '14 at 13:06
  • Then you're stuck with XML and polling, sorry. – Kayaman Apr 04 '14 at 13:09
  • Is there any kind of event listener which we can ask server to implement? – Nikhil Chilwant Apr 04 '14 at 13:23
  • No. If you were in charge of the server you could make a socket connection there, have the server output modified values when they come up, and just keep the connection open. But if you're not writing the server **then you're stuck with XML and polling**. – Kayaman Apr 04 '14 at 13:27

2 Answers2

1

Using jaxb, it will convert XML to java objects http://www.mkyong.com/java/jaxb-hello-world-example/

j.con
  • 879
  • 7
  • 19
1

Try XPath.

Off the top of my head, the expression for timestamp is

//Execution/@timestamp

and HIGHACTIVE text node:

//Execution/text()
Community
  • 1
  • 1
NickJ
  • 9,380
  • 9
  • 51
  • 74