• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to search content of tags using Java?

 
John Best
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friends,

My first ever post to this resourceful forum..

Is it possible to search the Content on XML tags using Java and XPath..?

The XML file is like -

<RegNo>1</RegNo>
<RegDate>02-Oct-2011</RegDate>
<RegDescription>The registration is done on 2nd october 2011 between house owner and tenant. The registration is valid upto 2012.
The house owner is Mr. XYZ and the tenant is Mr. ABC. The first party lives in NY and the latter at CA.</RegDescription>
....


I will need to search the contents of the above XML file, especially the contents of the <RegDescription> tag.

For example...
I will need to find those <RegNo>'s where the registration is ending in 2012. The output would be 1 and so on...


Thanks in advance
Have a nice day
John

 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm assuming you will be using XPath 1.0, since you didn't specify. Anyway here's a link to XML Path Language (XPath) Version 1.0; follow its link to the chapter about string functions. You've got a length function and a substring function, that should be all you need to pick out the last four characters of a text node.

(I see that XPath 2.0 has an ends-with function, if you're going to be using that.)
 
John Best
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I'm assuming you will be using XPath 1.0, since you didn't specify. Anyway here's a link to XML Path Language (XPath) Version 1.0; follow its link to the chapter about string functions. You've got a length function and a substring function, that should be all you need to pick out the last four characters of a text node.

(I see that XPath 2.0 has an ends-with function, if you're going to be using that.)



Dear Paul,

Thanks for the reply... :thumbup:

I will be using XPath 2.0.
but .. how to find... am I using XPath 2.0 or XPath 1.0..?
because I got an error when used matches String function, which is with XPath 2.0.

BTW the main aim of this thread is solved. I am able to search the contents of the tags...


Have a nice day
John
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't know which you are using, that means you are using XPath 1.0.
 
John Best
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:If you don't know which you are using, that means you are using XPath 1.0.


Dear Paul,

Yes you are right... I am using XPath 1.0.

How can I use XPath 2.0..?


have a nice day
John
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic