trouble in getting pattern with regex
hello, I have two dimensional array dataX and it stores kinds of information as below
name = Redondo Peak
photo = Redondo peak-composite2.jpg
photo_caption =
elevation_ft = 11258
elevation_ref = {{NAVD88}}<ref name="ngs">
{{cite ngs
id = FO1482
.
.
.
and it goes like that for 40 peaks..
I want to get "name = ......." patterns to be able to handle each peak's name.
my code is like
REGEX = "(name)\\s+\\=\\s+[a-zA-Z0-9]+" ;
dataX = new String[temp.length][];
Pattern p = Pattern.compile(REGEX);
Matcher m ;
for ( String line : temp )
{
dataX[count++] = line.split("\\|\\s"); \\ puts data into array as I showed above
}
// I expect from the loop below to store name=...... values into data4 array string but does not work
for(int i=0,t=0; i<dataX.length; i++)
{
for(int j=0; j<dataX[i].length; j++)
{
m = p.matcher(dataX[i][j]);
while(m.find()) {
data4[t] = m.group() ;
t++;
}
}
}
for(int x =0; x <data4.length ; x++)
System.out.println(data4[x]); // throws nullpointer exception
any idea please ?
Re: trouble in getting pattern with regex
Who creates the source of the data? is it you or someone else?
Re: trouble in getting pattern with regex
i solved it thanks friend
the data actualy come from wiki dump xml file.
but I get the data from xml and split it. After splitting
I stored them into dataX two dimensional array.
thnks
Re: trouble in getting pattern with regex
Why didn't you just parse the XML to get the values directly?
There are tools in java to read XML files for you.
You could have read the values into objects and then write/map those objects to a database.
Read it: (don't ignore it)
A simple way to read an XML file in Java - Java sample code - developer Fusion
Re: trouble in getting pattern with regex
somer81, don't you think it's bad manners to ignore a response on an earlier thread and go ahead and post a new question? Surely ozzyman deserves to know whether his advice was appreciated.
db