root / branches / piloto3d / libraries / libCq CMS for java.old / src-test / org / cresques / io / datastruct / TestXMLParser.java @ 9523
History | View | Annotate | Download (2.54 KB)
1 |
/*
|
---|---|
2 |
* Created on 18-ago-2006
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*/
|
25 |
package org.cresques.io.datastruct; |
26 |
|
27 |
import java.io.File; |
28 |
import java.io.FileInputStream; |
29 |
import java.io.FileNotFoundException; |
30 |
import java.io.IOException; |
31 |
|
32 |
import org.kxml2.io.KXmlParser; |
33 |
import org.xmlpull.v1.XmlPullParserException; |
34 |
|
35 |
public class TestXMLParser { |
36 |
|
37 |
public TestXMLParser(){
|
38 |
boolean end = false; |
39 |
try{
|
40 |
KXmlParser parser = new KXmlParser();
|
41 |
parser.setInput(new FileInputStream("/home/maquerol/prueba.rmf"), null); |
42 |
|
43 |
int tag = parser.nextTag();
|
44 |
|
45 |
parser.require(KXmlParser.START_TAG, null, "RasterMetaFile"); |
46 |
while(!end){
|
47 |
tag = parser.next(); |
48 |
if (tag == parser.START_TAG){
|
49 |
if(tag == parser.TEXT) parser.next();
|
50 |
if((parser.getName().equals("Band"))){ |
51 |
parser.require(KXmlParser.START_TAG, null, "Band"); |
52 |
tag = parser.nextTag(); |
53 |
parser.require(KXmlParser.START_TAG, null, "Values"); |
54 |
System.out.println(parser.nextText() + "\n"); |
55 |
parser.require(KXmlParser.END_TAG, null, "Values"); |
56 |
tag = parser.nextTag(); |
57 |
parser.require(KXmlParser.END_TAG, null, "Band"); |
58 |
} |
59 |
if((tag == parser.END_TAG) && (parser.getName().equals("RasterMetaFile"))) |
60 |
end = true;
|
61 |
} |
62 |
} |
63 |
//String cadena = parser.nextText();
|
64 |
//System.out.println(cadena);
|
65 |
}catch(XmlPullParserException e){
|
66 |
System.err.println("Exception pull parser"); |
67 |
}catch(FileNotFoundException ex){ |
68 |
System.err.println("Exception no file"); |
69 |
}catch(IOException exc){ |
70 |
System.err.println("Exception can't read"); |
71 |
} |
72 |
} |
73 |
|
74 |
public static void main(String[] args){ |
75 |
TestXMLParser test = new TestXMLParser();
|
76 |
} |
77 |
|
78 |
} |