Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAXB Exception

 
Eshu San
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
im using jaxb to manipulate xml document.i created the schema classes from the xsd document.Im tring to run a program that's displaying the values in a xml document .my code goes like this:


public static void main(String srgs[]){
try{
JAXBContext jContext = JAXBContext.newInstance("generated");
Unmarshaller unmarshaller = jContext.createUnmarshaller();
//unmarshaller.setValidating(true); //LINE 1
PurchaseOrder purchaseorder = (PurchaseOrder)unmarshaller.unmarshal(new File("PurchaseOrder.xml"));
BillToType billto = purchaseorder.getBillTo();
System.out.println("Name:"+billto.getName());
System.out.println("Street:"+billto.getStreet());
System.out.println("City:"+billto.getCity());
System.out.println("State:"+billto.getState());
ItemsType items = purchaseorder.getItems();
List itemsList=items.getItem();
for(int i=0;i<itemsList.size();i++){
Item item=(Item)itemsList.get(i);
System.out.println("productName:"+item.getProductName());
System.out.println("Quantity:"+item.getQuantity());
System.out.println("Price:"+item.getPrice());
}
}

when my line 1 is commented im getting a perfect result.but when i include the line 1 im getting "JAXBException:unable to extract the schema information".can anyone pls tell me how to overcome this problem?
 
Rick Portugal
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say:

JAXBContext jContext = JAXBContext.newInstance("generated");

Are your JAXB-generated classes really in the "generated" folder? Are you sure they aren't in the current folder or some other folder? Should your code say soemthing like this instead?:

JAXBContext jContext = JAXBContext.newInstance("javaranch.generated");
 
Eshu San
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually my compiler generated schema classes are in the directory called "generated" .so i think that part of the program is correct.pls guide me if im wrong..

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic