P
pitthekid
Hello,
I discovered JAXB to Parse XML files. It is a fine thing and I tested
the examples of jwsdp-1.6/jaxb. All went ok, I created a xsd, a
build.xml which then created the nessecary Java Files.
Afterwards I created a simple xml file.
This is the xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
jxb:version="1.0">
<xs:element name="AERORDROME">
<xs:complexType>
<xs:sequence>
<xs:element name="RWY_ALOC_KEY" type="xs:int"/>
<xs:element name="RWY_ID" type="xs:int"/>
<xs:element name="RWY_LAST_UPDATE" type="xs:string"/>
<xs:element name="RWY_OPERATOR" type="xs:string"/>
<xs:element name="RWY_ILS_CAT" type="xs:string"/>
<xs:element name="RWY_LOC_IDENT" type="xs:string"/>
<xs:element name="RWY_LOC_TYPE" type="xs:string"/>
<xs:element name="RWY_LOC_FREQ" type="xs:int"/>
<xs:element name="RWY_LOC_DME_CHAN" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
this is an xml file:
<AERORDROME >
<RWY_ALOC_KEY>1</RWY_ALOC_KEY>
<RWY_ID>2</RWY_ID>
<RWY_LAST_UPDATE>RWY_LAST_UPDATE781-555-1212</RWY_LAST_UPDATE>
<RWY_OPERATOR>RWY_OPERATOR781-555-1212</RWY_OPERATOR>
<RWY_ILS_CAT>RWY_ILS_CAT781-555-1212</RWY_ILS_CAT>
<RWY_LOC_IDENT>RWY_LOC_IDENT781-555-1212</RWY_LOC_IDENT>
<RWY_LOC_TYPE>RWY_LOC_TYPE781-555-1212</RWY_LOC_TYPE>
<RWY_LOC_FREQ>4711</RWY_LOC_FREQ>
<RWY_LOC_DME_CHAN>RWY_LOC_DME_CHAN781-555-1212</RWY_LOC_DME_CHAN>
</AERORDROME>
Withinn a Java application I could read the Data of the xml file:
public static void main( String[] args ) {
try {
// create a JAXBContext capable of handling classes
generated into
// the example package
JAXBContext jc = JAXBContext.newInstance( "example" );
// create an Unmarshaller
Unmarshaller u = jc.createUnmarshaller();
// unmarshal a FooBar instance document into a tree of Java
content
// objects composed of classes from the example package.
AERORDROME aerodrome = (AERORDROME)u.unmarshal( new
FileInputStream( "fsi.xml" ) );
int RWY_ALOC_KEY = aerodrome.getRWYALOCKEY();
String RWY_LAST_UPDATE = aerodrome.getRWYLASTUPDATE();
String RWY_OPERATOR = aerodrome.getRWYOPERATOR();
String RWY_ILS_CAT = aerodrome.getRWYILSCAT();
String RWY_LOC_IDENT = aerodrome.getRWYLOCIDENT();
String RWY_LOC_TYPE = aerodrome.getRWYLOCTYPE();
int RWY_LOC_FREQ = aerodrome.getRWYLOCFREQ();
String RWY_LOC_DME_CHAN = aerodrome.getRWYLOCDMECHAN();
System.out.println("RWY_ALOC_KEY[" + RWY_ALOC_KEY + "]");
System.out.println("RWY_LAST_UPDATE[" + RWY_LAST_UPDATE +
"]");
System.out.println("RWY_OPERATOR[" + RWY_OPERATOR + "]");
System.out.println("RWY_ILS_CAT[" + RWY_ILS_CAT + "]");
System.out.println("RWY_LOC_IDENT[" + RWY_LOC_IDENT + "]");
System.out.println("RWY_LOC_TYPE[" + RWY_LOC_TYPE + "]");
System.out.println("RWY_LOC_FREQ[" + RWY_LOC_FREQ + "]");
System.out.println("RWY_ALOC_KEY[" + RWY_ALOC_KEY + "]");
System.out.println("RWY_LOC_DME_CHAN[" + RWY_LOC_DME_CHAN +
"]");
....
}
Now I would like to read from one big xml file with a structure like
<AERORDROMES >
<AERORDROME >
<RWY_ALOC_KEY>1</RWY_ALOC_KEY>
<RWY_ID>2</RWY_ID>
<RWY_LAST_UPDATE>RWY_LAST_UPDATE781-555-1212</RWY_LAST_UPDATE>
<RWY_OPERATOR>RWY_OPERATOR781-555-1212</RWY_OPERATOR>
<RWY_ILS_CAT>RWY_ILS_CAT781-555-1212</RWY_ILS_CAT>
<RWY_LOC_IDENT>RWY_LOC_IDENT781-555-1212</RWY_LOC_IDENT>
<RWY_LOC_TYPE>RWY_LOC_TYPE781-555-1212</RWY_LOC_TYPE>
<RWY_LOC_FREQ>4711</RWY_LOC_FREQ>
<RWY_LOC_DME_CHAN>RWY_LOC_DME_CHAN781-555-1212</RWY_LOC_DME_CHAN>
</AERORDROME>
<AERORDROME >
<RWY_ALOC_KEY>1</RWY_ALOC_KEY>
<RWY_ID>3</RWY_ID>
<RWY_LAST_UPDATE>RWY_LAST_UPDATE781-555-1212</RWY_LAST_UPDATE>
<RWY_OPERATOR>RWY_OPERATOR781-555-1212</RWY_OPERATOR>
<RWY_ILS_CAT>RWY_ILS_CAT781-555-1212</RWY_ILS_CAT>
<RWY_LOC_IDENT>RWY_LOC_IDENT781-555-1212</RWY_LOC_IDENT>
<RWY_LOC_TYPE>RWY_LOC_TYPE781-555-1212</RWY_LOC_TYPE>
<RWY_LOC_FREQ>4711</RWY_LOC_FREQ>
<RWY_LOC_DME_CHAN>RWY_LOC_DME_CHAN781-555-1212</RWY_LOC_DME_CHAN>
</AERORDROME>
.....
<AERORDROMES >
How can I realize this, or better how can I parse it?
Thanks for help.
Yours, Pitthekid.
I discovered JAXB to Parse XML files. It is a fine thing and I tested
the examples of jwsdp-1.6/jaxb. All went ok, I created a xsd, a
build.xml which then created the nessecary Java Files.
Afterwards I created a simple xml file.
This is the xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
jxb:version="1.0">
<xs:element name="AERORDROME">
<xs:complexType>
<xs:sequence>
<xs:element name="RWY_ALOC_KEY" type="xs:int"/>
<xs:element name="RWY_ID" type="xs:int"/>
<xs:element name="RWY_LAST_UPDATE" type="xs:string"/>
<xs:element name="RWY_OPERATOR" type="xs:string"/>
<xs:element name="RWY_ILS_CAT" type="xs:string"/>
<xs:element name="RWY_LOC_IDENT" type="xs:string"/>
<xs:element name="RWY_LOC_TYPE" type="xs:string"/>
<xs:element name="RWY_LOC_FREQ" type="xs:int"/>
<xs:element name="RWY_LOC_DME_CHAN" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
this is an xml file:
<AERORDROME >
<RWY_ALOC_KEY>1</RWY_ALOC_KEY>
<RWY_ID>2</RWY_ID>
<RWY_LAST_UPDATE>RWY_LAST_UPDATE781-555-1212</RWY_LAST_UPDATE>
<RWY_OPERATOR>RWY_OPERATOR781-555-1212</RWY_OPERATOR>
<RWY_ILS_CAT>RWY_ILS_CAT781-555-1212</RWY_ILS_CAT>
<RWY_LOC_IDENT>RWY_LOC_IDENT781-555-1212</RWY_LOC_IDENT>
<RWY_LOC_TYPE>RWY_LOC_TYPE781-555-1212</RWY_LOC_TYPE>
<RWY_LOC_FREQ>4711</RWY_LOC_FREQ>
<RWY_LOC_DME_CHAN>RWY_LOC_DME_CHAN781-555-1212</RWY_LOC_DME_CHAN>
</AERORDROME>
Withinn a Java application I could read the Data of the xml file:
public static void main( String[] args ) {
try {
// create a JAXBContext capable of handling classes
generated into
// the example package
JAXBContext jc = JAXBContext.newInstance( "example" );
// create an Unmarshaller
Unmarshaller u = jc.createUnmarshaller();
// unmarshal a FooBar instance document into a tree of Java
content
// objects composed of classes from the example package.
AERORDROME aerodrome = (AERORDROME)u.unmarshal( new
FileInputStream( "fsi.xml" ) );
int RWY_ALOC_KEY = aerodrome.getRWYALOCKEY();
String RWY_LAST_UPDATE = aerodrome.getRWYLASTUPDATE();
String RWY_OPERATOR = aerodrome.getRWYOPERATOR();
String RWY_ILS_CAT = aerodrome.getRWYILSCAT();
String RWY_LOC_IDENT = aerodrome.getRWYLOCIDENT();
String RWY_LOC_TYPE = aerodrome.getRWYLOCTYPE();
int RWY_LOC_FREQ = aerodrome.getRWYLOCFREQ();
String RWY_LOC_DME_CHAN = aerodrome.getRWYLOCDMECHAN();
System.out.println("RWY_ALOC_KEY[" + RWY_ALOC_KEY + "]");
System.out.println("RWY_LAST_UPDATE[" + RWY_LAST_UPDATE +
"]");
System.out.println("RWY_OPERATOR[" + RWY_OPERATOR + "]");
System.out.println("RWY_ILS_CAT[" + RWY_ILS_CAT + "]");
System.out.println("RWY_LOC_IDENT[" + RWY_LOC_IDENT + "]");
System.out.println("RWY_LOC_TYPE[" + RWY_LOC_TYPE + "]");
System.out.println("RWY_LOC_FREQ[" + RWY_LOC_FREQ + "]");
System.out.println("RWY_ALOC_KEY[" + RWY_ALOC_KEY + "]");
System.out.println("RWY_LOC_DME_CHAN[" + RWY_LOC_DME_CHAN +
"]");
....
}
Now I would like to read from one big xml file with a structure like
<AERORDROMES >
<AERORDROME >
<RWY_ALOC_KEY>1</RWY_ALOC_KEY>
<RWY_ID>2</RWY_ID>
<RWY_LAST_UPDATE>RWY_LAST_UPDATE781-555-1212</RWY_LAST_UPDATE>
<RWY_OPERATOR>RWY_OPERATOR781-555-1212</RWY_OPERATOR>
<RWY_ILS_CAT>RWY_ILS_CAT781-555-1212</RWY_ILS_CAT>
<RWY_LOC_IDENT>RWY_LOC_IDENT781-555-1212</RWY_LOC_IDENT>
<RWY_LOC_TYPE>RWY_LOC_TYPE781-555-1212</RWY_LOC_TYPE>
<RWY_LOC_FREQ>4711</RWY_LOC_FREQ>
<RWY_LOC_DME_CHAN>RWY_LOC_DME_CHAN781-555-1212</RWY_LOC_DME_CHAN>
</AERORDROME>
<AERORDROME >
<RWY_ALOC_KEY>1</RWY_ALOC_KEY>
<RWY_ID>3</RWY_ID>
<RWY_LAST_UPDATE>RWY_LAST_UPDATE781-555-1212</RWY_LAST_UPDATE>
<RWY_OPERATOR>RWY_OPERATOR781-555-1212</RWY_OPERATOR>
<RWY_ILS_CAT>RWY_ILS_CAT781-555-1212</RWY_ILS_CAT>
<RWY_LOC_IDENT>RWY_LOC_IDENT781-555-1212</RWY_LOC_IDENT>
<RWY_LOC_TYPE>RWY_LOC_TYPE781-555-1212</RWY_LOC_TYPE>
<RWY_LOC_FREQ>4711</RWY_LOC_FREQ>
<RWY_LOC_DME_CHAN>RWY_LOC_DME_CHAN781-555-1212</RWY_LOC_DME_CHAN>
</AERORDROME>
.....
<AERORDROMES >
How can I realize this, or better how can I parse it?
Thanks for help.
Yours, Pitthekid.