• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String parsing help.

 
Ranch Hand
Posts: 185
Netbeans IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have an xml formatted string that I need to extract information from.



I can read the file into the String 's' no problem. Is there any way to find the index of the character where s.contains finds the <PhoneNumber> tag? Bascially I have to extract the phone number inside the tag and since the contains method finds the tag so quickly it would be great if I could get the index where it locates the tag and start reading the phone number into a seperate string from there.

Thanks,
Alan
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alan Smith wrote:Is there any way to find the index of the character where s.contains finds the <PhoneNumber> tag?


Yes, but my suggestion would be to use a proper XML parser like SAX. The sort of stuff you want is exactly what it was designed for.

Winston
 
Alan Smith
Ranch Hand
Posts: 185
Netbeans IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Alan Smith wrote:Is there any way to find the index of the character where s.contains finds the <PhoneNumber> tag?


Yes, but my suggestion would be to use a proper XML parser like SAX. The sort of stuff you want is exactly what it was designed for.
Winston



My problem is that I have to read the xml file in as a string first and then parse the string. Basically I have thousands of strings formatted as xml that I have to parse. I can't save all the strings as .xml files first and then parse them.
 
Ranch Hand
Posts: 344
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use javax.xml.parsers.DocumentBuilder to convert the String into an XML Document.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alan Smith wrote:My problem is that I have to read the xml file in as a string first and then parse the string. Basically I have thousands of strings formatted as xml that I have to parse. I can't save all the strings as .xml files first and then parse them.



So what? XML parsers can read from strings, too.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alan Smith wrote:Is there any way to find the index of the character where s.contains finds the <PhoneNumber> tag?


I find it odd that you didn't find any method of String that matches the two words I underlined.
reply
    Bookmark Topic Watch Topic
  • New Topic