Solved

xml Split lines

Posted on 2006-07-11
5
248 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
ID: 17088243
which vesion of the jre will the app run on?
0
 
LVL 9

Accepted Solution

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

Expert Comment

by:riaancornelius
ID: 17088352
on previous versions you can use a StringTokenizer.
0
 
LVL 35

Expert Comment

by:girionis
ID: 17088453
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
ID: 17088680
String[] tmp = e.getTextContent().split("\\s*");

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
network + 7 79
groupSum5 challenge 5 67
mapAB Challlenge 35 123
Unable to start eclipse ? 17 127
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

947 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

22 Experts available now in Live!

Get 1:1 Help Now