Help on jaxb

I am new to JAXB, I would like to seek help from you guys.
my requirement is, I would like to write an xsd schema for the xml file (tree structure )which is given below .
Xml sample:
<data language="English">-----------------1
     <datalink type="navigational" template="templateid">-------------1.1
          <name>String</name>
          <detaildescription>String</detaildescription>
          <image>String</image>
          <datalink type="navigational" template="templateid">-----------1.1.1
               <name>String</name>
               <detaildescription>String</detaildescription>
               <image>String</image>
               <datalink type="terminal" template="templateid">     
                    <name>String</name>
                    <detaildescription>String</detaildescription>
                    <image>String</image>
                    <page>
                         <header>String</header>
                         <shortdescription>String</shortdescription>
                         <image>String</image>
                         <imagedescription>String</imagedescription>
                    </page>
               </datalink>
          </datalink>-------------end of 1.1.1
     </datalink>----------------end of 1.1
     <datalink type="terminal" template="templateid">-------------1.2
          <name>String</name>
          <detaildescription>String</detaildescription>
          <image>String</image>
          <page>
               <header>String</header>
               <shortdescription>String</shortdescription>
               <image>String</image>
               <imagedescription>String</imagedescription>
          </page>
     </datalink>----------end of 1.2
</data>-----------------end of 1
There are basically two nodes, one is navigational which contains description about the node (i.e. name, detaildescription, image) and also information about the child nodes.
Second one is a Terminal node, which is some what similar to leaf node.
Navigational node must contain atleast one terminal node and it can have 'n' number of either navigation node or Terminal nodes (similar to tree structure).
I would like to write an xsd for above mentioned tree structure and would like to use jaxb to create java equivalent objects. I would like to know how can I implement schema for recursive loop (tree structure) and would like to know whether I can use jaxb for this purpose or I have to use anything else?.
Thank you.
Regards,
Ramki.

A schema element with elements with same name and different complexType
generates error:
"Elements with the same name and in the same scope must have the same type."
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE xs:schema PUBLIC '-//W3C//DTD XMLSCHEMA 200102//EN'
'http://www.w3.org/2001/XMLSchema.dtd'
>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="data">
<xs:complexType>
<xs:sequence>
<xs:element name="datalink" type="navigational"/>
<xs:element name="datalink" type="terminal"/>
</xs:sequence>
<xs:attribute name="language"/>
</xs:complexType>
</xs:element>
<xs:complexType name="navigational">
<xs:sequence>
<xs:element name="datalink" type="navigational" minOccurs="0" maxOccurs="1"/>
<xs:element name="datalink" type="terminal" minOccurs="0" maxOccurs="1"/>
<xs:element name="name"/>
<xs:element name="detaildescription"/>
<xs:element name="image"/>
</xs:sequence>
<xs:attribute name="type" type="xs:string"/>
<xs:attribute name="template" type="xs:string"/>
</xs:complexType>
<xs:complexType name="terminal">
<xs:sequence>
<xs:element name="name"/>
<xs:element name="detaildescription"/>
<xs:element name="image"/>
<xs:element name="page">
<xs:complexType>
<xs:sequence>
<xs:element name="header"/>
<xs:element name="shortdescription"/>
<xs:element name="image"/>
<xs:element name="imagedescription"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="type" type="xs:string"/>
<xs:attribute name="template" type="xs:string"/>
</xs:complexType>
</xs:schema>

Similar Messages

  • Need urgent help on JAXB !!

    I'm new to JAXB and in urgent need of help. Here's my problem.
    I have a schema which has a child node "node1".
    "node1" can occur once or multiple times.
    My Input
    Now, I receive an xml with 5 occurrences of "node1".
    My Required Output
    I need to create 5 xmls (same schema) with 1 occurrence of "node1".
    Please help me with solution(s).
    Thanks a ton in advance
    :)

    Also you can ask at Java Technology & XML forum:
    http://forum.java.sun.com/forum.jspa?forumID=34

  • Help with Jaxb - AnyType access to sub-elements?

    Hi All,
    I am reading an XML file (defined with XML Schema) using Jaxb.
    I need one particular element to hold an arbitrary, but well formed, XML document (with any tags).
    As such I've defined this element to be of the type xs:anyType. (See payload)
    The AnyType Jaxb class however only appears to be giving me access to the text node strings (not sub-elements). (Notice its don't see <b> needs help </b>)
    I need the whole thing so I can pass it on to another parser.
    Any ideas? Is this supported in jaxb? Is this supported by XML Schema? Am I doing something wrong?
    See details below.
    Thanks!
    mike
    THE SCHEMA:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema elementFormDefault="qualified"
               attributeFormDefault="unqualified"
               jaxb:version="1.0"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
            <xs:element name="message" type="message"/>
            <xs:complexType name="message">
                    <xs:annotation>
                            <xs:appinfo>
                                    <jaxb:class name="XmlMessage"/>
                            </xs:appinfo>
                    </xs:annotation>
                    <xs:sequence>
                            <xs:element name="from" type="xs:string"/>
                            <xs:element name="to" type="xs:string"/>
                            <xs:element name="send-date" type="xs:date"/>
                            <xs:element name="payload" type="xs:anyType"/>
                    </xs:sequence>
            </xs:complexType>
    </xs:schema>
    THE DOCUMENT:
    <?xml version="1.0" encoding="UTF-8"?>
    <message xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="message.xsd">
         <from>Mike</from>
         <to>Java Community</to>
         <send-date>2006-03-23</send-date>
         <payload>Mike<b> needs help </b>parsing the AnyType</payload>
    </message>
    THE CODE:
            // get the fields
            String from = xmlMessage.getFrom();
            String to = xmlMessage.getTo();
            Calendar date = xmlMessage.getSendDate();
            AnyType payload = xmlMessage.getPayload();
            // print out the values
            System.out.println("FROM: " + from);
            System.out.println("TO: " + to);
            System.out.println("DATE: " + date.getTime());
            System.out.println("PAYLOAD: " + payload);
            // print out details regarding the payload (The AnyType list)
            System.out.println("\tAnyType list length = "
                    + payload.getContent().size());
            for (Iterator i = payload.getContent().iterator(); i.hasNext();) {
                Object o = i.next();
                System.out.println("\t" + o.getClass() + " : \"" + o + "\"");
            } THE OUTPUT:
    FROM: Mike
    TO: Java Community
    DATE: Wed Mar 22 19:00:00 EST 2006
    PAYLOAD: org.w3._2001.xmlschema.impl.AnyTypeImpl@1c99159
         AnyType list length = 2
         class java.lang.String : "Mike"
         class java.lang.String : "parsing the AnyType"

    Ok.
    source message:
    root
    - node0 (first instance)
    --- node1
    name="<b>key</b>"
    value="<b>my_key_value_1</b>"
    --- /node1
    --- node1
    name="attribute1"
    value="attribute1_value"
    --- /node1
    --- /node0
    - node0 (second instance)
    --- node1
    name="<b>key</b>"
    value="<b>my_key_value_2</b>"
    --- /node1
    --- node1
    name="attribute1"
    value="attribute1_value"
    --- /node1
    - /node0
    /root
    Desired destination message:
    root
    - node0 (first instance)
    - key_value=<b>my_key_value_1</b> <- does exist
    --- node1
    name="<b>key</b>"
    value="<b>my_key_value_1</b>"
    --- /node1
    --- node1
    name="attribute1"
    value="attribute1_value"
    --- /node1
    - /node0
    - node0 (second instance)
    - key_value=<b>my_key_value_2</b>  < should exist but does <u>not</u> exist
    --- node1
    name="<b>key</b>"
    value="<b>my_key_value_2</b>"
    --- /node1
    --- node1
    name="attribute1"
    value="attribute1_value"
    --- /node1
    - /node0
    /root

  • Urgent Help on JAXB Validation - Please Help

    I have an application that needs validation before marshalling a content tree. If the tree is not valid, I need to marshall the tree and look at the problem in the XML file itself.
    If it's a valid XML file, then continue as usual...
    These is the pseudo code.. But don't know if I can implement it with JAXB or not....And how to implement it..
    populate XML tree
    check if the tree is valid or not
    if it is valid continue processing
    if not valid, marshall the tree into an XML file and analyze the
    problem
    Any input is welcome...
    Thanks in advance..

    svenkatesh s, thanks for your reply. In addition to your suggestion,
    I found this method:
    public class ValidationHelper implements ValidationEventHandler {
    public boolean handleEvent(ValidationEvent arg0) {
         System.out.println("The message is: " + arg0.getMessage());
         System.out.println("The severity is: " + arg0.getSeverity());
         ValidationEventLocator locator = arg0.getLocator();
         System.out.println("The column number: " + locator.getColumnNumber());
         System.out.println("The line number: " + locator.getLineNumber());
              Node nd = locator.getNode();
              log.write(Logger.LOG_INFO, "The node: " + nd);
              String st = nd.getNodeName();
              log.write(Logger.LOG_INFO, "Node Name " + st);
              String stt = nd.getNodeValue();
              log.write(Logger.LOG_INFO, "Node Value: " + stt);
              return true;
    I noticed that Node is null, but it might be a test data problem...

  • Help find JAXB mistake..

    Hi,
    I have a schema looks like this.
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" jaxb:version="1.0">
         <xs:element name="authorDetails" type="author-details-type"/>
         <xs:complexType name="author-details-type">
              <xs:sequence>
                   <xs:element name="author" type="authorType" maxOccurs="unbounded"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="authorType">
              <xs:sequence>
         <xs:element name="author_type" type="xs:string"/>
         <xs:element name="author_name" type="xs:string"/>
         <xs:element name="author_email" type="xs:string"/>
         <xs:element name="author_ph_no" type="xs:string"/>
         <xs:element name="author_organization" type="xs:string"/>
         </xs:sequence>
         <xs:attribute name="author_id" type="xs:ID" use="required"/>
         </xs:complexType>
    </xs:schema>
    When I try to add a same record twice using JAXB, it doesn't complain about the duplication but does it the third time. My insert method looks like this. I have tried validating both before and after marshalling, but it's the same result. I also tried to check if the value AuthorID already exists in the list before inserting, but it returns false. Can anyone point the mistake I am making here that I am not able to find.
    JAXBContext jaxbCntxt = JAXBContext.newInstance("dhs.familynet.feedback.author");
    author.ObjectFactory objFactory = new .author.ObjectFactory();
    //Creating an object of insertElement class that contains this method
    insertElement ie = new insertElement();
    // Call Unmarshaller method in my class to create umnarsha object
    Unmarshaller authorDetailsUnmarshaller = ie.createUnmarshallerObject();
    // Create a validator
    Validator authorDetailsValidator = jaxbCntxt.createValidator();
    author.AuthorDetails authDetails= (author.AuthorDetails)
    authorDetailsUnmarshaller.unmarshal(new File("authorDetails.xml"));
    author.AuthorType AuthorTypeObject = objFactory.createAuthorType();
    System.out.println("Validator returned " + authorDetailsValidator.validate(authDetails));
    authDetails = (author.AuthorDetails) authorDetailsUnmarshaller.unmarshal(new File("authorDetails.xml"));
    List authList = authDetails.getAuthor();
    AuthorTypeObject.setAuthorPhNo("230-89-34342");
    AuthorTypeObject.setAuthorOrganization("ASFaf");
    AuthorTypeObject.setAuthorName("Re");
    AuthorTypeObject.setAuthorType("User3");
    AuthorTypeObject.setAuthorId("o");
    AuthorTypeObject.setAuthorEmail("ASFaf@home");
    authList.add(AuthorTypeObject);
    System.out.println("Validator returned " + authorDetailsValidator.validate(authDetails));
    System.out.println("Created a content tree and marshalled it to Authoutput.xml");
    Marshaller authorDetailsMarshaller = ie.createMarshallerObject();
    authorDetailsMarshaller.marshal(authDetails, new FileOutputStream("authorDetails.xml"));
    THanks

    Thanks for responding..This is the error I get the THIRD TIME I run with same values for all items.
    DefaultValidationEventHandler: [ERROR]: "o" is used as an ID value more than once.
    com.sun.msv.verifier.ValidityViolation: "o" is used as an ID value more than once.
    at com.sun.msv.verifier.Verifier.onError(Verifier.java:319)
    at com.sun.msv.verifier.Verifier.endDocument(Verifier.java:383)
    at com.sun.msv.verifier.VerifierFilter.endDocument(VerifierFilter.java:82)
    at org.iso_relax.verifier.impl.ForkContentHandler.endDocument(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.endDocument(AbstractSAXParser.java:708)
    at org.apache.xerces.impl.XMLDocumentScannerImpl.endEntity(XMLDocumentScannerImpl.java:530)
    at org.apache.xerces.impl.XMLEntityManager.endEntity(XMLEntityManager.java:1503)
    at org.apache.xerces.impl.XMLEntityManager$EntityScanner.load(XMLEntityManager.java:3564)
    at org.apache.xerces.impl.XMLEntityManager$EntityScanner.skipSpaces(XMLEntityManager.java:32
    34)
    at org.apache.xerces.impl.XMLDocumentScannerImpl$TrailingMiscDispatcher.dispatch(XMLDocument
    ScannerImpl.java:1102)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentSca
    nnerImpl.java:346)
    at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:529)
    at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:585)
    at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1142)
    at com.sun.xml.bind.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:130)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:1
    39)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:1
    44)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:1
    53)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:1
    71)
    at dhs.familynet.feedback.insertElement.insert(insertElement.java:77)
    at dhs.familynet.feedback.test.main(test.java:30)
    --------------- linked to ------------------
    javax.xml.bind.UnmarshalException
    - with linked exception:
    [com.sun.msv.verifier.ValidityViolation: "o" is used as an ID value more than once.]
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarsha
    llerImpl.java:306)
    at com.sun.xml.bind.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:134)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:1
    39)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:1
    44)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:1
    53)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:1
    71)
    at dhs.familynet.feedback.insertElement.insert(insertElement.java:77)
    at dhs.familynet.feedback.test.main(test.java:30)

  • Help w/ JAXB

    I am having a hard time figuring out how to use JAXB to generate some java classes for my XML schema. I have been able to run the schema thru JAXB and generate some java code. Unfortunately, the code generated by JAXB will not let me generate the XML I need.
    Here is my XML Schema (atleast the part that I'm stuck on):
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema targetNamespace="_one_" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:_two_="_two_">
    <xs:element name="Packet" type="_two_:Packet"/>
    <xs:complexType name="Packet" abstract="true"/>
    <xs:complexType name="RequestPacket">
    <xs:complexContent>
    <xs:extension base="_two_:Packet">
    <xs:sequence>
    <xs:element name="Requests">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="Request" type="_two_:Request" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <xs:unique name="RequestPacket.Requests.Request.ID">
    <xs:selector xpath="damir:Request"/>
    <xs:field xpath="_two_:ID"/>
    </xs:unique>
    </xs:element>
    </xs:sequence>
    </xs:extension>
    </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="Request" abstract="true">
    <xs:sequence>
    <xs:element name="ID" type="xs:long"/>
    </xs:sequence>
    </xs:complexType>
    Here is what I'm trying to generate in my java code:
    <?xml version="1.0" encoding="UTF-8"?>
    <Packet xmlns="_two_" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="RequestPacket">
    <Requests>
    </Requests>
    </Packet>
    The problem is I can't get the XML to have both a Packet and a RequestPacket element. If I try to create a packet using the object factory, I can't add Requests to it.
    If I create Requests from the factory, I can add individual Request elements to Requests and everything is fine from that point on.
    Also, I am not given the option to set the attribute xsi:type and not all the xml namespaces are being set in the code.
    Does anyone know how I can get things working?

    Full Schema (it is valid according to XMLSpy)
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema targetNamespace="namespace:foo" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:foo="namespace:foo">
         <xs:element name="fooPacket" type="foo:fooPacket"/>
         <xs:complexType name="fooPacket" abstract="true"/>
         <xs:complexType name="RequestPacket">
              <xs:complexContent>
                   <xs:extension base="foo:fooPacket">
                        <xs:sequence>
                             <xs:element name="Requests">
                                  <xs:complexType>
                                       <xs:sequence>
                                            <xs:element name="Request" type="foo:Request" maxOccurs="unbounded"/>
                                       </xs:sequence>
                                  </xs:complexType>
                                  <xs:unique name="RequestPacket.Requests.Request.ID">
                                       <xs:selector xpath="foo:Request"/>
                                       <xs:field xpath="foo:ID"/>
                                  </xs:unique>
                             </xs:element>
                        </xs:sequence>
                   </xs:extension>
              </xs:complexContent>
         </xs:complexType>
         <xs:complexType name="Request" abstract="true">
              <xs:sequence>
                   <xs:element name="ID" type="xs:long"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="ResponsePacket">
              <xs:complexContent>
                   <xs:extension base="foo:fooPacket">
                        <xs:sequence>
                             <xs:element name="Responses">
                                  <xs:complexType>
                                       <xs:sequence>
                                            <xs:element name="Response" type="foo:Response" maxOccurs="unbounded"/>
                                       </xs:sequence>
                                  </xs:complexType>
                                  <xs:unique name="ResponsePacket.Responses.Response.ID">
                                       <xs:selector xpath="foo:Response"/>
                                       <xs:field xpath="foo:ID"/>
                                  </xs:unique>
                             </xs:element>
                        </xs:sequence>
                   </xs:extension>
              </xs:complexContent>
         </xs:complexType>
         <xs:complexType name="Response" abstract="true">
              <xs:sequence>
                   <xs:element name="ID" type="xs:long"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="UnsupportedResponse">
              <xs:complexContent>
                   <xs:extension base="foo:Response"/>
              </xs:complexContent>
         </xs:complexType>
         <xs:complexType name="ErrorResponse">
              <xs:complexContent>
                   <xs:extension base="foo:Response">
                        <xs:sequence>
                             <xs:element name="Message" type="xs:string"/>
                        </xs:sequence>
                   </xs:extension>
              </xs:complexContent>
         </xs:complexType>
         <xs:complexType name="EchoRequest">
              <xs:complexContent>
                   <xs:extension base="foo:Request">
                        <xs:sequence>
                             <xs:element name="Message" type="xs:string"/>
                        </xs:sequence>
                   </xs:extension>
              </xs:complexContent>
         </xs:complexType>
         <xs:complexType name="EchoResponse">
              <xs:complexContent>
                   <xs:extension base="foo:Response">
                        <xs:sequence>
                             <xs:element name="Message" type="xs:string"/>
                        </xs:sequence>
                   </xs:extension>
              </xs:complexContent>
         </xs:complexType>
         <xs:complexType name="DataResponse">
              <xs:complexContent>
                   <xs:extension base="foo:Response">
                        <xs:sequence>
                             <xs:element name="DataPoints">
                                  <xs:complexType>
                                       <xs:sequence>
                                            <xs:element name="DataPoint" type="foo:DataPoint" minOccurs="0" maxOccurs="unbounded"/>
                                       </xs:sequence>
                                  </xs:complexType>
                             </xs:element>
                        </xs:sequence>
                   </xs:extension>
              </xs:complexContent>
         </xs:complexType>
         <xs:complexType name="DataPoint" abstract="true">
              <xs:sequence>
                   <xs:element name="Sequence" type="xs:long"/>
              </xs:sequence>
         </xs:complexType>
    </xs:schema>
    Sample XML object that I'm trying to build:
    <?xml version="1.0" encoding="UTF-8"?>
    <fooPacket xmlns="namespace:foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ResponsePacket">
         <Responses>
              <Response xsi:type="EchoResponse">
                   <ID>2</ID>
                   <Message>This is a test of the Echo functionality</Message>
              </Response>
         </Responses>
    </fooPacket>

  • Help Regarding JAXB

    How can I bind schema or DTD through Java Code. Can anybody say where to pass the schema or DTD as parameter to get the related classes or interfaces.
    Regards
    happymuna

    Essentially the same as http://forum.java.sun.com/thread.jspa?threadID=579338&messageID=2921525#2921525

  • JAXB Unmarshalling complexity

    Hello all,
    I need help on JAXB
    the situation is as below...
    i have to write a program that communicates with a server. the communication is request-response kind of communication which is to be carried out through XML.
    so everytime i have to send any request i need to create an XML and then send it to the server. i get the response in the form of XML. then i have to parse the XML to find out whats the response.
    previously i used DOM and SAX for creating XML and parsing XML respectively.
    now every response i get, i have to validate it against a DTD.
    now i'm trying out JAXB. so i first converted all the DTDs to XSD (xml schema docs). because JAXB doesn't support DTDs.
    now with JAXB, i'm creating the XML requests and sending it to the server and getting the response.
    but here is one problem.....
    as with JAXB, of i have to unmarshall the xml response i have to first create a JAXB context. and unmarshall it to that xml object that i'm expecting. but suppose i get some other response then how am i supposed to know that.
    i'll explain the above with a small example.
    suppose i have the following DTDs
    SearchRequest.dtd..............for search requests
    SearchResponse.dtd..............for search responses
    ErrorResponse.dtd.............for if the server sends any error.
    now first i convert this DTDs to XSDs and so i get
    SearchRequest.xsd, SearchResponse.xsd, ErrorResponse.xsd
    and then using the JAXB compiler i create the JAXB derived classes in the following package
    com.xyz.SearchRequest
    com.xyz.SearchResponse
    com.xyz.ErrorResponse
    now suppose i created the xml request and sent it to the server and i got the response. and i have to unmarshall it.
    (the server will send me SearchResponse.xml if everything if fine but ErrorResponse.xml it theres an error).
    now heres the problem. the server will send the SearchResponse or ErrorResponse. and ill have to determine what it is before i start to unmarshall.
    i hope i have communicated my problem....
    thankyou
    java-jones

    Not sure if this will help you or if this is what you are looking for, but from the JAXB Users' Guide:
    More About Unmarshalling
    The Unmarshaller class in the javax.xml.bind package provides the client application the ability to convert XML data into a tree of Java content objects. The unmarshal method for a schema (within a namespace) allows for any global XML element declared in the schema to be unmarshalled as the root of an instance document. The JAXBContext object allows the merging of global elements across a set of schemas (listed in the contextPath). Since each schema in the schema set can belong to distinct namespaces, the unification of schemas to an unmarshalling context should be namespace-independent. This means that a client application is able to unmarshal XML documents that are instances of any of the schemas listed in the contextPath; for example:
    JAXBContext jc = JAXBContext.newInstance( "com.acme.foo:com.acme.bar" );
    Unmarshaller u = jc.createUnmarshaller();
    FooObject fooObj = (FooObject)u.unmarshal( new File( "foo.xml" ) ); // ok
    BarObject barObj = (BarObject)u.unmarshal( new File( "bar.xml" ) ); // ok
    BazObject bazObj = (BazObject)u.unmarshal( new File( "baz.xml" ) ); // error

  • WTF DO THESE JAXB INSTALLATION NOTES MEAN?

    Hello,
    I need help installing JAXB, since i don't understand the installation instructions:
    My JAXB is located in the directory "C:\jaxb-1.0-ea" and java is located at "C:\jdk1.3.1_02"
    Could somebody please explain these 3 steps to me? thanks!!
    (1). Define the environment variable JAVA_HOME to name the location of your previously-installed J2SE distribution, for example, /usr/local/jdk1.3.1.
    (2). Assuming that $DIR names the directory in which you unbundled the release, define a shell alias xjc that expands to $DIR/jaxb-1.0-ea/bin/xjc.
    (3). Define the environment variable CLASSPATH to have the value .:$DIR/jaxb-1.0-ea/lib/jaxb-rt-1.0-ea.jar.thanks for your help!

    hi, thanks for your help but im still confused on some parts:
    (1). Define the environment variable JAVA_HOME to name the location of your previously->>intalled J2SE distribution, for example, /usr/local/jdk1.3.1.The command for this step will look something like
    this
    set JAVA_HOME=C:\jdk1.3.1_02
    This basically sets the environment variable to the
    value "C:\jdk1.3.1_02". JAXB will access this
    environment variable to access the javac,java,....Q. where do i do this at? on the PATH?
    (2). Assuming that $DIR names the directory in which
    you unbundled the release, define a shell alias xjc
    that expands to $DIR/jaxb-1.0-ea/bin/xjc.The command for this step will look something like
    this
    set xjc=C:\jaxb-1.0-ea\jaxb-1.0-ea\bin\xjcQ. where do i define a shell alias? and what does that mean?
    (3). Define the environment variable CLASSPATH to have the value.:$DIR/jaxb-1.0-ea/lib/jaxb-rt-1.0-ea.jar.Q. So i just add C:\\jaxb-1.0-ea/lib/jaxb-rt-1.0-ea.jar; to my classpath?
    thanks

  • Signer Information does not match

    hi,
    i am using JAXB for my application
    using xsd to i got the java classes and interfaces with the help of JAXB tool.
    i can use those type of classes and interface in my project. normally those classes and interface are stored in com.ct.common package.and it work good.
    afterthat i created one class(without help of xsd) and this class location is also same (com.ct.common). but i can't use that class. if i use it throws
    java.lang.SecurityException: class "com.ct.common.AppenderFile"'s signer information does not match signer information of other classes in the same packagehelp me. how can i use that class?

    open the corresponding jar file and delete META-INF folder. It might work. Its merely a guess :)

  • Help in resolving JAXB issue.

    HI
    I have an element called currency which has a default value as "USD".
    The xml schema entry for this element is as shown below:
    <xsd:element name="currency" type="xsd:string" default ="USD" />
    when i generate JAXB objects, the default value for this element is not getting initialized to the variable defined for this element.
    can anyone help me in getting this information into the JAXB object that gets generated by xjc.
    do i need to provide any custom binging configuration for this.
    Thanks in advance.
    Bala

    I have the same problem.
    I tried to reset without resolving.
    I tried also to remove Whatsapp and viber, than changed the current date to a date in the past, I installed Whatsapp and Viber and accepted the push notification. Also in this the problem is not resolved.
    I confirm that the problem started after the update to ios 8.1
    Regards

  • JAXB  I realy need you help

    JAXB I realy need you help
    Dear friend
    We have next structure of XML file
    <order>
    <entities>
    <entity>1</entity>
    <entity>2</entity>
    <entity>3</entity>
    </entities>
    </order>
    according to xml we generate XSD
    after that use xjc.exe for generate JAXB Objects
    Class Order
    Entities entities
    Class Entities
    List<Entity> entity
    but I would like to be like that
    Class Order
    List<Entity> entity
    Class Entities make transient or use JAXB Custome mapping or other decision
    Thanks

    that is the standard way jaxb generates the model classes. i believe there is some sort of experimental "use simple mappings" switch (probably a vendor extension) which makes the xml files cleaner (similar to your desired implementation), but i don't have much experience with it.

  • JAXB help please

    Can i use JAXB to remove an Element in the XML file? For example, in the Purchase Order, is there anyway that i can delete
    <billTo country="US">
    <name>Robert Smith</name>
    <street>8 Oak Avenue</street>
    <city>Cambridge</city>
    <state>MA</state>
    <zip>12345</zip>
    </billTo>
    this whole junk from the XML file ?
    Thanx for your help
    _old man
    <?xml version="1.0"?>
    <purchaseOrder orderDate="1999-10-20">
    <shipTo country="US">
    <name>Alice Smith</name>
    <street>123 Maple Street</street>
    <city>Cambridge</city>
    <state>MA</state>
    <zip>12345</zip>
    </shipTo>
    <billTo country="US">
    <name>Robert Smith</name>
    <street>8 Oak Avenue</street>
    <city>Cambridge</city>
    <state>MA</state>
    <zip>12345</zip>
    </billTo>
    <items>
         <item partNum="242-NO" >
              <productName>Nosferatu - Special Edition (1929)</productName>
              <quantity>5</quantity>
              <USPrice>19.99</USPrice>
         </item>
         <item partNum="242-MU" >
              <productName>The Mummy (1959)</productName>
              <quantity>3</quantity>
              <USPrice>19.98</USPrice>
         </item>
         <item partNum="242-GZ" >
              <productName>Godzilla and Mothra: Battle for Earth/Godzilla vs. King Ghidora</productName>
              <quantity>3</quantity>
              <USPrice>27.95</USPrice>
         </item>
         </items>
    </purchaseOrder>

    Not directly, but yes.
    You can use JAXB to load the file (you'll need to have compiled the schema, so JAXB knows the format of the file), then delete the object from the Java object holding it, then use JAXB to write the file back out again.

  • JAXB Help

    im looking to do following
    I have a XSD . I want to manipulate JAva beans representing the XSD complex types in Java, at runtime , set values in the beans, and then easily generate a XML string out of the java bean
    The xml string if written to file must be a valid XML document.
    1) can i use JAXB for this
    2) any code samples, or pointers to tutorials will really help
    thanks

    We are using JAXB through Top Link.
    What you have to do is to generate the java bean class corresponding to your xml schema using the jaxb compilator in Jdeveloper.
    We have seen that the element in the xml schema has to be defined as global or reference a simple or complex type to generated correctly as a class we will have to use later as data control.
    Create a java bean that reference you main object class and load the document, by example in the getter.
    public Classification getClassificationDocument() {
    try {
    //Create a JAXBContext instance
    jaxbContext = JAXBContext.newInstance("classification.toplinkInterface");
    // get the xml document file
    file = new java.io.File(this.pathXML);
    if (file.exists() == true) {
    // create the unmarhaller objet to read the document
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    // read the document into the objet that represent the document structure
    classificationDocument =
    (Classification)unmarshaller.unmarshal(file);
    } catch (Exception e) {
    e.printStackTrace();
    return classificationDocument;
    Use that java bean to generate a data control.
    Be careful to the interface that are generated with java.array.util.list that are not typped. For them you have typped manually or you declare the corresponding bean class in the data control xml file corresponding the that iterator.
    <?xml version="1.0" encoding="UTF-8" ?>
    <JavaBean xmlns="http://xmlns.oracle.com/adfm/beanmodel" version="10.1.3.39.84"
    id="ClassificationLanguageType"
    BeanClass="classification.toplinkInterface.ClassificationLanguageType"
    Package="classification.toplinkInterface" isJavaBased="true">
    <Attribute Name="classificationLanguageCode" Type="java.lang.String"/>
    <Attribute Name="classificationLanguageLabel" Type="java.lang.String"/>
    </JavaBean>
    Note also that jdeveloper don't create a data control file for the implementation file and will need it at execution time. Be sure to create a data control manually for the implementation class you will use. classification.toplinkInterface.ClassificationLanguageType is the interface, so i will have to create a data control for classification.toplinkInterface.impl.ClassificationLanguageTypeImpl too.
    <?xml version="1.0" encoding="UTF-8" ?>
    <JavaBean xmlns="http://xmlns.oracle.com/adfm/beanmodel" version="10.1.3.39.84"
    id="ClassificationLanguageTypeImpl"
    BeanClass="classification.toplinkInterface.impl.ClassificationLanguageTypeImpl"
    Package="classification.toplinkInterface.impl" isJavaBased="true">
    <Attribute Name="classificationLanguageCode" Type="java.lang.String"/>
    <Attribute Name="classificationLanguageLabel" Type="java.lang.String"/>
    <ConstructorMethod IsCollection="false" Type="void"
    id="ClassificationLanguageTypeImpl"/>
    </JavaBean>
    Hope this will help you ...
    <?xml version="1.0" encoding="UTF-8" ?>
    <JavaBean xmlns="http://xmlns.oracle.com/adfm/beanmodel" version="10.1.3.39.84"
    id="ClassificationLanguageTypeImpl"
    BeanClass="classification.toplinkInterface.impl.ClassificationLanguageTypeImpl"
    Package="classification.toplinkInterface.impl" isJavaBased="true">
    <Attribute Name="classificationLanguageCode" Type="java.lang.String"/>
    <Attribute Name="classificationLanguageLabel" Type="java.lang.String"/>
    <ConstructorMethod IsCollection="false" Type="void"
    id="ClassificationLanguageTypeImpl"/>
    </JavaBean>
    Note that we are using jxpath too search node in the xml document with xpath. That is very very very useful.
    Here is an example that search for all main-title in french as a pointer, get the title value and get the correponding identification to generate an alphabetic index from a hierarchical structure.
    Hope this will help you

  • Help needed on JAXB 2.0

    Hi,
    I am trying to generate java classes from a simple catalog.xsd file.
    The output is below.
    Directory of E:\jaxbsamples\schema
    11/13/2007 04:24 PM <DIR> .
    11/13/2007 04:24 PM <DIR> ..
    11/13/2007 04:12 PM 971 catalog.xsd
    11/13/2007 04:30 PM <DIR> generated
    11/13/2007 02:56 PM 1,647 Lesson.java
    2 File(s) 2,618 bytes
    3 Dir(s) 9,440,661,504 bytes free
    E:\jaxbsamples\schema>xjc catalog.xsd
    parsing a schema...
    compiling a schema...
    generated\ArticleType.java
    generated\CatalogType.java
    generated\JournalType.java
    generated\ObjectFactory.java
    The directory impl and runtime directory under impl and the respective java files never get generated.
    Not sure what the problem is . My class path is below
    CLASSPATH=E:\jaxbsamples;E:\Java\jwsdp-2.0\jaxb\lib\jaxb-api.jar;E:\Java\jwsdp-2
    .0\jaxb\lib\jaxb-impl.jar;E:\Java\jwsdp-2.0\jaxb\lib\jaxb-libs.jar;E:\Java\jwsdp
    -2.0\jaxb\lib\jaxb-xjc.jar;E:\Java\jwsdp-2.0\jswdp-shared\lib\namespace.jar;E:\J
    ava\jwsdp-2.0\jwsdp-shared\lib\jax-qname.jar;E:\Java\jwsdp-2.0\jwsdp-shared\lib\
    xsdlib.jar;E:\Java\jdk1.6.0_02\lib\tools.jar;E:\Java\jwsdp-2.0\jwsdp-shared\lib\
    relaxngDatatype.jar;E:\Java\jwsdp-2.0\jaxp\lib\jaxp.jar;E:\Java\jwsdp-2.0\jaxp\l
    ib\endorsed\dom.jar;E:\Java\jwsdp-2.0\jaxp\lib\endorsed\sax.jar;E:\Java\jwsdp-2.
    0\jaxp\lib\endorsed\xalan.jar;E:\Java\jwsdp-2.0\jaxp\lib\endorsed\xercesImpl.jar
    I am using jwsdp2.0 and JDK 1.6 update 2.
    Any help is greatly appreciated.
    Thanks
    Srikant

    hi srikant,
    u r using jaxb2.0 as part of jwsdp2.0.
    when u try to generate jaxb classes with .xsd file using jaxb2.0, u will never get those impl as well as runtime folders created and files under them. Jaxb2.0 has feature to bind these data in the few files generated.
    If u really want these files generated, try using jaxb1.0 or jaxb 1.0.x
    See the below topic pasted by me for compatability issues:
    http://forum.java.sun.com/thread.jspa?threadID=5235499&tstart=0
    topic name:what is the jaxb version compatible with jdk1.3
    reply back if u have any questions...
    hema

Maybe you are looking for

  • Calendar List View MISSING in iOS 7.1 on iPhone 4S

    The old way to get list view was to tap the magnifying lens. Since 7.1 there is supposed to be a red button that toggles list view and month calendar + partial (smailler) list view. The icons for these are 3 lines for List View and a small rectangle

  • Mail not working after upgrade to Leopard

    After the guy at the applestore assuring me that mail will not be affected by upgrading, low and behold I now have lost all emails and am unable to send or receive emails. When I open mail it leaves the interface closed, I need to go to MAIL > NEW VI

  • EREC: Wrong client in PR approval URL

    Hi We make client copy from client 600 to 700. Now when we release personal requisition in client 700, it is not appearing for approval in recruiters URL. It can be found in user's SAP business workplace as workflow work item. When we execute that wo

  • How do I switch Travel Time in Mac Calendar from work to home?

    I recently installed Mavericks and have been using the new Travel Time feature in Calendar.  Today I ran into a problem, however.  I scheduled an appointment and put in the location address.  When I went to enter the travel time, it only gave me two

  • [svn:fx-4.0.0] 13417: remove references to charts samples since we aren' t using these particular samples any longer.

    Revision: 13417 Revision: 13417 Author:   [email protected] Date:     2010-01-11 08:50:21 -0800 (Mon, 11 Jan 2010) Log Message: remove references to charts samples since we aren't using these particular samples any longer. QE notes: Doc notes: Bugs: