<?xml version="1.0" encoding="UTF-8"?> <!-- Document ...

weaverchurchSoftware and s/w Development

Aug 15, 2012 (5 years and 2 months ago)

303 views





<?xml version="1.0" encoding="UTF
-
8"?>


<!
--


Document : courselist.xml


Created : 6. februar 2009, 17:59


Author
: Administrator


Description: Purpose of the document follows.

--
>


<courselist xmlns:xsi
='http://www.w3.org/2001/XMLSchema
-
instance'


xmlns='http://xml.netbeans.org/schema/s2jcoursexml'


xsi:schemaLocation='http://xml.netbeans.org/schema/s2jcoursexml courselist.xsd'>


<course>


<title>SWC1.1</title>


<name>Software Constr
uction</name>


<semester>1</semester>


</course>


<course>


<title>SWC1.2</title>


<name>Software Construction</name>


<semester>2</semester>


</course>


<course>


<title>SWD1.1</title>


<name>Software
Design</name>


<semester>1</semester>


</course>


<course>


<title>SWD1.2</title>


<name>Software Design</name>


<semester>2</semester>


</course>

</courselist>




<?xml version="1.0" encoding="UTF
-
8"?>


<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"


targetNamespace="http://xml.netbeans.org/schema/s2jcoursexml"


xmlns:tns="http://xml.netbeans.org/schema/s2jcoursexml"


elementFormDefault="qualified">


<xsd:complexType name="course">


<xsd:
sequence>


<xsd:element name="title" type="xsd:string" minOccurs="1"/>


<xsd:element name="name" type="xsd:string" minOccurs="1"/>


<xsd:element name="semester" type="xsd:int" minOccurs="1"/>


</xsd:sequence>


</x
sd:complexType>


<xsd:element name="courselist">


<xsd:complexType>


<xsd:sequence>


<xsd:element name="course" type="tns:course" minOccurs="0" maxOccurs="unbounded"/>


</xsd:sequence>


</xsd:complexType>


</xsd
:element>

</xsd:schema>



package jaxbtest;


import org.netbeans.xml.schema.s2jcoursexml.Course;

import org.netbeans.xml.schema.s2jcoursexml.Courselist;


public class Main {



public static void main(String[] args) {


Courselist c1 = new
Courselist();




try {


javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(c1.getClass().getPackage().getName());


javax.xml.bind.Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller();


c1

= (Courselist) unmarshaller.unmarshal(new java.io.File("courselist.xml")); //NOI18N


} catch (javax.xml.bind.JAXBException ex) {


// XXXTODO Handle exception


java.util.logging.Logger.getLogger("global").log(java.util.logg
ing.Level.SEVERE, null, ex); //NOI18N


}



for (Course c : c1.getCourse()) {


System.out.println("Title: " + c.getTitle());


System.out.println("Name: " + c.getName());


System.out.println("Semester: " +
c.getSemester());


}



Course course = new Course();


course.setName("Webprogramming");


course.setTitle("WEBP");


course.setSemester(4);



c1.getCourse().add(course);



for (Course c : c1.getCourse()) {



System.out.println("Title: " + c.getTitle());


System.out.println("Name: " + c.getName());


System.out.println("Semester: " + c.getSemester());


}



try {


javax.xml.bind.JAXBContext jaxbCtx =


java
x.xml.bind.JAXBContext.newInstance(course.getClass().getPackage().getName());


javax.xml.bind.Marshaller marshaller = jaxbCtx.createMarshaller();


marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF
-
8"); //NOI18N



marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);


marshaller.marshal(c1, System.out);


} catch (javax.xml.bind.JAXBException ex) {


// XXXTODO Handle exception


java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, null, ex); //NOI18N


}


}

}




//

// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson
-
jaxb
-
ri
-
2.2
-
147

// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>

// Any modifications to this file will be lost upon recompilation of the source schema.

// Generated on: 2010.03.24 at 04:59:38 PM CET

//


package org.netbeans.xml.schema.s2j
coursexml;


import javax.xml.bind.annotation.XmlAccessType;

import javax.xml.bind.annotation.XmlAccessorType;

import javax.xml.bind.annotation.XmlElement;

import javax.xml.bind.annotation.XmlType;



/**


* <p>Java class for course complex type.


*


* <p>T
he following schema fragment specifies the expected content contained within this class.


*


* <pre>


* &lt;complexType name="course">


* &lt;complexContent>


* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">


* &lt;sequence>


* &lt;element name="title" type="{http://www.w3.org/2001/XMLSchema}string"/>


* &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>


* &lt;element name="semester" type="{http://www.w3.org/2001/XMLSchema}int"/
>


* &lt;/sequence>


* &lt;/restriction>


* &lt;/complexContent>


* &lt;/complexType>


* </pre>


*


*


*/

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "course", propOrder = {


"title",


"name",


"semester"

})

public

class Course {



@XmlElement(required = true)


protected String title;


@XmlElement(required = true)


protected String name;


protected int semester;



/**


* Gets the value of the title property.


*


* @return


*
possible object is


* {@link String }


*


*/


public String getTitle() {


return title;


}



/**


* Sets the value of the title property.


*


* @param value


* allowed object is


* {@link St
ring }


*


*/


public void setTitle(String value) {


this.title = value;


}



/**


* Gets the value of the name property.


*


* @return


* possible object is


* {@link String }


*


*/


public String getName() {


return name;


}



/**


* Sets the value of the name property.


*


* @param value


* allowed object is


* {@link String }


*


*/


public void setName(String value) {



this.name = value;


}



/**


* Gets the value of the semester property.


*


*/


public int getSemester() {


return semester;


}



/**


* Sets the value of the semester property.


*


*/


public void
setSemester(int value) {


this.semester = value;


}


}



//

// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson
-
jaxb
-
ri
-
2.2
-
147

// See <a href="http://java.sun.com/xml/jaxb">
http://java.sun.com/xml/jaxb</a>

// Any modifications to this file will be lost upon recompilation of the source schema.

// Generated on: 2010.03.24 at 04:59:38 PM CET

//



package org.netbeans.xml.schema.s2jcoursexml;


import java.util.ArrayList;

impor
t java.util.List;

import javax.xml.bind.annotation.XmlAccessType;

import javax.xml.bind.annotation.XmlAccessorType;

import javax.xml.bind.annotation.XmlRootElement;

import javax.xml.bind.annotation.XmlType;



/**


* <p>Java class for anonymous complex type
.


*


* <p>The following schema fragment specifies the expected content contained within this class.


*


* <pre>


* &lt;complexType>


* &lt;complexContent>


* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">


* &lt;sequence>


* &lt;element name="course" type="{http://xml.netbeans.org/schema/s2jcoursexml}course" maxOccurs="unbounded" minOccur
s="0"/>


* &lt;/sequence>


* &lt;/restriction>


* &lt;/complexContent>


* &lt;/complexType>


* </pre>


*


*


*/

@
XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "", propOrder = {


"course"

})

@XmlRootElement(name = "courselist")

public class Courselist {



protected List<Course> course;



/**


* Gets the value of the course property.


*


*
<p>


* This accessor method returns a reference to the live list,


* not a snapshot. Therefore any modification you make to the


* returned list will be present inside the JAXB object.


* This is why there is not a <CODE>set</CODE>

method for the course property.


*


* <p>


* For example, to add a new item, do as follows:


* <pre>


* getCourse().add(newItem);


* </pre>


*


*


* <p>


* Objects of the following type(s) are allowed in the list


* {@link Course }


*


*


*/


public List<Course> getCourse() {


if (course == null) {


course = new ArrayList<Course>();


}


return this.c
ourse;


}


}