• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

xml Split lines

Hi.
I have a xml tag like this:
<ot>54231
76541
89621</ot>
I can read this tag in to org.w3c.dom.Element e, and then convert it to a String using e.getTextContent().

But I can't figure out how to split this textContent into String[];
I use both windows and Solaris, so I need something that works on both platforms.
0
kristian_gr
Asked:
kristian_gr
  • 3
1 Solution
 
riaancorneliusCommented:
which vesion of the jre will the app run on?
0
 
riaancorneliusCommented:
on 1.5 you can use String[] tmp = e.getTextContent().split("\n");
0
 
riaancorneliusCommented:
on previous versions you can use a StringTokenizer.
0
 
girionisCommented:
You could also try

StringTokenizer st = new StringTokenizer(e.getTextContent());
String [] tokens = new String[st.countTokens()];
int counter = 0;
     while (st.hasMoreTokens()) {
         tokens[counter] = st.nextToken();
         counter++;
     }
0
 
CEHJCommented:
String[] tmp = e.getTextContent().split("\\s*");

may be better if tabs or other whitespace are involved too
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now