Solved

xml Split lines

Posted on 2006-07-11
5
247 Views
Last Modified: 2010-04-16
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
Comment
Question by:kristian_gr
  • 3
5 Comments
 
LVL 9

Expert Comment

by:riaancornelius
Comment Utility
which vesion of the jre will the app run on?
0
 
LVL 9

Accepted Solution

by:
riaancornelius earned 500 total points
Comment Utility
on 1.5 you can use String[] tmp = e.getTextContent().split("\n");
0
 
LVL 9

Expert Comment

by:riaancornelius
Comment Utility
on previous versions you can use a StringTokenizer.
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
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
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
String[] tmp = e.getTextContent().split("\\s*");

may be better if tabs or other whitespace are involved too
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now