Results 1 to 3 of 3

Thread: Jaxb

  1. #1
    unknownuser is offline Member
    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0

    Default Jaxb

    Hey ,Can any one help me.
    I need to fecth data from more than one table using hibernate and create xml by using JAXB.

    I have fecthed data in hashmap now can anyone help me in how to use JAXB for creating xml with xsd validation.

  2. #2
    Join Date
    Oct 2008
    Posts
    73
    Rep Power
    0

    Default Re: Jaxb

    You can try with below sample code:

    public static void parseRequestXML(String xml) throws Exception {
    final Unmarshaller unmarshaller = reqJAXBContext.createUnmarshaller();
    final StringReader reader = new StringReader(xml);
    objOfClass = (class) unmarshaller.unmarshal(reader);
    }
    -----------------------------------------

    public static JAXBContext reqJAXBContext = null;
    SchemaFactory schemafactory = null;
    String schema_Language = "http://www.w3.org/2001/XMLSchema";

    schemafactory = SchemaFactory.newInstance(schema_Language);
    reqJAXBContext = JAXBContext.newInstance(ClassName.class);

    Schema schema = null;
    String errmsg = null;
    try {
    schema = sf.newSchema(schemaFile);
    } catch (SAXException e) {
    // Invalid schema file
    errmsg = e.getMessage();
    }
    Validator validator = schema.newValidator();
    InputStream is = new ByteArrayInputStream(xml.getBytes());
    Source source = new StreamSource(is);
    try {
    validator.validate(source);
    } catch (SAXException e) {
    // Invalid XML received

    e.printStackTrace();
    }
    Rakesh Mehta

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Jaxb

    70 posts, been around since 2008 and you still have not learned how to post code huh.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. JAXB type help!!!
    By mafyou in forum XML
    Replies: 1
    Last Post: 04-23-2012, 10:53 AM
  2. JAXB Unmarshalling
    By milan.nosal in forum XML
    Replies: 0
    Last Post: 09-01-2010, 02:15 PM
  3. JAXB Binding
    By Fusebox in forum XML
    Replies: 0
    Last Post: 06-11-2010, 10:06 PM
  4. Jaxb
    By Paul Richards in forum XML
    Replies: 1
    Last Post: 08-03-2009, 09:56 PM
  5. JAXB Unmarshalling
    By prateek in forum XML
    Replies: 0
    Last Post: 07-10-2008, 06:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •