File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes How to search content of tags using Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to search content of tags using Java?" Watch "How to search content of tags using Java?" New topic
Author

How to search content of tags using Java?

John Best
Greenhorn

Joined: Oct 02, 2011
Posts: 9
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
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

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

Joined: Oct 02, 2011
Posts: 9
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
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

If you don't know which you are using, that means you are using XPath 1.0.
John Best
Greenhorn

Joined: Oct 02, 2011
Posts: 9
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
 
jQuery in Action, 2nd edition
 
subject: How to search content of tags using Java?