kristian_gr
asked on
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.
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.
which vesion of the jre will the app run on?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
on previous versions you can use a StringTokenizer.
You could also try
StringTokenizer st = new StringTokenizer(e.getTextC ontent());
String [] tokens = new String[st.countTokens()];
int counter = 0;
while (st.hasMoreTokens()) {
tokens[counter] = st.nextToken();
counter++;
}
StringTokenizer st = new StringTokenizer(e.getTextC
String [] tokens = new String[st.countTokens()];
int counter = 0;
while (st.hasMoreTokens()) {
tokens[counter] = st.nextToken();
counter++;
}
String[] tmp = e.getTextContent().split(" \\s*");
may be better if tabs or other whitespace are involved too
may be better if tabs or other whitespace are involved too