aspose file tools*
The moose likes Beginning Java and the fly likes How do i convert a string to string array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do i convert a string to string array" Watch "How do i convert a string to string array" New topic
Author

How do i convert a string to string array

Aditya Sirohi
Ranch Hand

Joined: Jan 05, 2010
Posts: 93

Hello all,

This is my first positing on the forum and i am new to Java Programming. I have been using XPath API to parse for some tags in the XML file and write it to the file using File Reader/Writer. The problem is that this line of code:- String result = xPath.evaluate("/su/@id", new InputSource(new FileReader("/net/7.1_TESTFIX_CQ/nt_i386/ShareableEntities/"+j1))); returns string. I want to write this to a string[] so that i can write this to a file. So write now the text file myfile.txt only has one entry which is the last entry, where as it should have more than 100 entries. How do i do that. I am copying the method. Help is very appreciated!!!


Thanks
Aditya




(Edited to reduce the width of the code -- PC)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18993
    
    8

Once you tell XPath to lump your results together into a String, there's no easy way to get that mess unscrambled. If you expect XPath to return a nodeset, then tell it you want a nodeset:

Now you will have a list of nodes to iterate over.
Aditya Sirohi
Ranch Hand

Joined: Jan 05, 2010
Posts: 93

Hello Paul,

The suggestion you gave me, i could find a work around with that, so what i did, i wrote i different method which stored the path to the XML file in the text file. I modified this method i posted above to get the valie from the "id" attribute and store it the the test file sucessfully.

Thanks
Aditya
Aditya Sirohi
Ranch Hand

Joined: Jan 05, 2010
Posts: 93

Thanks Paul
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do i convert a string to string array