Hello All,
I have attached the Schema which I am using. I am trying to create a content tree by using the following java code below. Before creating the content tree, I have parsed the XML Schema and got the JAXB classes. I have to genetate the following content tree, but my program below doesnot do that. Please check this piece of code and tell me where I am making a mistake? Is the Schema wrong or the Java Program I have written is wrong. Please help me out.
Thanks,
Sarada.
<?xml version="1.0" encoding="UTF-8"?>
<Collection xmlns:jxb="
http://java.sun.com/xml/ns/jaxb" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\WebServices\work\Test.xsd">
<Choice snumber="0">
<answerchoice>String</answerchoice>
</Choice>
</Collection>
/////////////////////////////////////JAVA PROGRAM
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.math.*;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.Marshaller;
import test.jaxb.*;
public class New
{
public static void main( String[] args )
{
try
{
JAXBContext jc = JAXBContext.newInstance( "test.jaxb" );
ObjectFactory objFactory = new ObjectFactory();
Marshaller mar = jc.createMarshaller();
mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT ,new Boolean(true));
CollectionType ctype = objFactory.createCollectionType();
Collection cc = objFactory.createCollection();
List lst1 = ctype.getChoice();
ChoiceType chtype = objFactory.createChoiceType();
Choice ch1 = objFactory.createChoice();
chtype.setSnumber(1);
chtype.setAnswerchoice("Old");
lst1.add(chtype);
mar.marshal(ctype, System.out);
}
catch( JAXBException je )
{
je.printStackTrace();
}
catch( Exception ioe )
{
ioe.printStackTrace();
}
}
}
- application/octet-stream attachment: Test.xsd