JAXB vs. xs:Time

Hello,
I'm trying to read XML file using JAXB.
The problem is when I'm trying to parse tag that have XML type xs:time I receve a null as XMLGregorianCalendar from this field because it represented as <TimeTag>14:00:00-06:00</TimeTag> without year-month-day. I can read it properly just if I set this tag as <TimeTag>06-02-01T14:00:00-06:00</TimeTag>
How can I read fields that have just time information using JAXB?

thanks, but following that link we can see that this is a valid time:
<Time>14:00:00-06:00</Time>
Isn't it?
But when I try to read this tag using JAXB a receive null pointer.
Somebody read the XML with datatype xs:time using JAXB?

Similar Messages

  • Problem in JAXB for processing XML files

    hello
    I have been working on a project where i need to process data in XML format. the flow goes thus
    I have 28 data elements that i need to represent as a XML so i compile the schema files and generate the class files for each of the tags and thus i can use the get and set methods to read and write to a XML file respectively(example getName and setName)......
    Now the problem is that my coding is done if i change my xml file and add say 2 more tags how do i handle it in my code.........
    1>Do i have recomplie the schema file and generate new class files every time the xml structure changes. can i avoid this recompiling process and use a one time genrated class files even if the xml structure changes.
    2>Now i have hard coded the get and set methods for processing the xml file if i add new tags to my xml i wouldnt have the get set methods for the new tags in my code(say i add a new tag as Phone then i wouldnt have the codes getPhone and setPhone called in my code and this tage was added after the coding was done)........how do i handle this situation. Is is possible that i can get and set data without using these methods and use some sort of a dynamic way of getting and setting data.............
    3>Any other approach available to meet the above requirements other than JAXB.
    Please help for the above problem
    Thank you

    hi,
    i had written a xml and schema to validate.
    my xml would be
    <output>
    <table>
    <row>
    <column></column>
    <column></column>
    </row>
    </table>
    <document>
    <properties>
    </properties>
    <contents>
    </contents>
    </document>
    <table>
    <row>
    <column></column>
    <column></column>
    </row>
    </table>
    <document>
    <properties>
    </properties>
    <contents>
    </contents>
    </document>
    <table>
    <row>
    <column></column>
    <column></column>
    </row>
    </table>
    <document>
    <properties>
    </properties>
    <contents>
    </contents>
    </document>
    </output>
    schema should validate : each table should contain atleast one row element and each row element should have atleast one column. similarly, each document should have atleast one properties and contents element.
    if any of these things occur. for ex: if there is no row element in table, i need to delete the table tag. similary if there is no properties/content or both element in document it should delete the corresponding document from the xml.
    i tried for table if there is no row element am getting the line number of the </table> tag, based on that am deleting the table element. if there is no properties tag and contents tag is there. am getting the line number for <contents>start tag, with which i could not able to delete the whole document.
    can anybody plz help me out for this requirement

  • Parsing Problem in JAXB

    Hi, I am getting run time exception. I have kept all 4 jar files in classpath..
    Exception::javax.xml.bind.JAXBException: Provider com.sun.xml.bind.ContextFactor
    y_1_0_1 not found
    - with linked exception:
    [java.lang.ClassNotFoundException: com.sun.xml.bind.ContextFactory_1_0_1]
    Exception in thread "main" java.lang.NullPointerException
    at com.veritas.ProcessItem.readItem(ProcessItem.java:117)
    at com.veritas.ProcessItem.<init>(ProcessItem.java:86)
    at com.veritas.ProcessItem.main(ProcessItem.java:126)
    So wht could be the reason??
    Thanks
    Chintan

    I've the same problem, but in java 6.
    The jaxb jars are included in jdk6, right?

  • Compile time error

    I am a newbie in XML. I am trying to compile the following code. I am getting compile time errors. I have following environment varaibles set. Any help will be really appreciated.
    TIA.
    set JAVA_HOME=C:\Program Files\jdk1.3.1_03
    set JWSDP_HOME=C:\Program Files\jwsdp-1.1
    set JAXB_HOME=%JWSDP_HOME%\jaxb-1.0
    set JAXB_LIBS=%JAXB_HOME%\lib
    set JAXP_LIBS=%JWSDP_HOME%\jaxp-1.2.2\lib
    set JWSDP_LIBS=%JWSDP_HOME%\jwsdp-shared\lib
    set PATH=%JAVA_HOME%\bin;%JAXB_HOME%\bin;%JWSDP_HOME%\jwsdp-shared\bin;%PATH%
    set CLASSPATH=%JAXB_LIBS%\jaxb-api.jar;%JAXB_LIBS%\jaxb-ri.jar;%JAXB_LIBS%\jaxb-xjc.jar;%JAXB_LIBS%\jaxb-libs.jar;%JAXP_LIBS%\jaxb-api.jar;%JAXP_LIBS%\endorsed\xercesImpl.jar;%JAXP_LIBS%\endorsed\xalan.jar;%JAXP_LIBS%\endorsed\sax.jar;%JAXP_LIBS%\endorsed\dom.jar;%JWSDP_LIBS%\jax-qname.jar;%JWSDP_LIBS%namespace.jar;.
    C:\Learn XML>javac -verbose CountSax.java
    [parsing started CountSax.java]
    [parsing completed 63ms]
    CountSax.java:3: package org.xml.sax does not exist
    import org.xml.sax.* ;
    ^
    CountSax.java:4: package org.xml.sax.helpers does not exist
    import org.xml.sax.helpers.* ;
    ^
    CountSax.java:5: package javax.xml.parsers does not exist
    import javax.xml.parsers.*;
    ^
    CountSax.java:7: cannot resolve symbol
    symbol : class DefaultHandler
    location: class CountSax
    public class CountSax extends DefaultHandler {
    ^
    [loading C:\jdk1.3.1_02\jre\lib\rt.jar(java/lang/String.class)]
    CountSax.java:22: cannot resolve symbol
    symbol : class Attributes
    location: class CountSax
    public void startElement(String name,Attributes atts) {
    import java.io.* ;
    import org.xml.sax.* ;
    import org.xml.sax.helpers.* ;
    import javax.xml.parsers.*;
    public class CountSax extends DefaultHandler {
    public static void main(String args[]) {
    SAXParserFactory factory = SAXParserFactory.newInstance() ;
    SAXParser saxParser = factory.newSAXParser() ;
    saxParser.parse(new File(args[0]),new CountSax()) ;
    static private int eltCount = 0 ;
    public void startDocument() {
    eltCount = 0 ;
    public void startElement(String name,Attributes atts) {
    eltCount ++ ;
    public void endDocument() {
    System.out.println("Total number of elements: " + eltCount) ;
    }

    Here is my classpath now
    set CLASSPATH=%JAVA_HOME%;%JAXB_LIBS%\jaxb-api.jar;%JAXB_LIBS%\jaxb-ri.jar;%JAXB_LIBS%\jaxb-xjc.jar;%JAXB_LIBS%\jaxb-libs.jar;%JAXP_LIBS%\jaxb-api.jar;%JAXP_LIBS%\endorsed\xercesImpl.jar;%JAXP_LIBS%\endorsed\xalan.jar;%JAXP_LIBS%\endorsed\sax.jar;%JAXP_LIBS%\endorsed\dom.jar;%JWSDP_LIBS%\jax-qname.jar;%JWSDP_LIBS%namespace.jar;.
    It still doesn't work. The pakages that it is complaining about comes from sax.jar which is already in classpath. Can anybody please help.
    TIA

  • JAXB Implemetation

    Hi All,
    I have a few doubts related to the above mentioned topic. Any help would be greatly appreciated.
    Doubt 1
    We are trying to use JAXB to implement Mapping Program in Java. I was wondering as to how and where should we put those files in the XI server.
    To explain it further :
    We have extracted all JAXB related and Mapping Application related files into a single folder and imported that folder as an archive into the XI Framework within the Software Component Version Namespace in the Integration Builder (Design). But, the message mapping in the SXMB_MONI is showing the following stack:
      <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Request Message Mapping
      -->
    - <SAP:ErrorHeader xmlns:SAP="http://sap.com/exchange/MessageFormat">
      <SAP:Context />
      <SAP:Code p1="Error during mapping" p2="--- Creating Java mapping com/wk/sapcl/mf/translator/source/SourceTranslator --- Using MappingResolver with context URL /sapmnt/XD1/global/xi/mapping/ATOSTOSAP/666d2600d4e811d8c989d1fc143c3524/ --- Loaded class com.wk.sapcl.mf.translator.source.SourceTranslator --- Using MappingResolver with context URL /sapmnt/XD1/global/xi/mapping/ATOSTOSAP/666d2600d4e811d8c989d1fc143c3524/ --- Load of javax/xml/bind/UnmarshalException.class from /sapmnt/XD1/global/xi/mapping/ATOSTOSAP/666d2600d4e811d8c989d1fc143c3524/ failed. --- Class not found: javax.xml.bind.UnmarshalException --- LinkageError at RUMappingJava.instantiate(): Could not instantiate class: com/wk/sapcl/mf/translator/source/SourceTranslator javax/xml/bind/UnmarshalException --- com.sap.aii.ibrun.server.map.MappingRuntimeException: at com.sap.aii.ibrun.server.map.MappingRuntimeException.code_STYLESHEET_OR_CLASS_NOT_FOUND(MappingRuntimeException.java:91) at com.sap.aii.ibrun.server.map.RUMappingJava.instantiate(RUMappingJava.java:158) at com.sap.aii.ibrun.server.map.RUMappingJava.execute(RUMappingJava.java:41) at com.sap.aii.ibrun.server.map.RURunner.run(RURunner.java:58) at com.sap.aii.ibrun.server.map.RUManager.run(RUManager.java:66) at com.sap.aii.ibrun.sbeans.map.MappingRequestHandler.handleRequest(MappingRequestHandler.java:67) at com.sap.aii.ibrun.sbeans.map.MappingServiceImpl.processFunction(MappingServiceImpl.java:83) at com.sap.aii.ibrun.sbeans.map.XMappingServiceObjectImpl0.processFunction(XMappingServiceObjectImpl0.java:24) at com.sap.aii.ibrun.sbeans.map.MappingServiceKey.processFunction(MappingServiceKey.java:10) at java.lang.reflect.Method.invoke(Native Method) at com.inqmy.services.rfcengine.RFCDefaultRequestHandler.invokeBean(RFCDefaultRequestHandler.java:83) at com.inqmy.services.rfcengine.RFCDefaultRequestHandler.handleRequest(RFCDefaultRequestHandler.java:50) at com.inqmy.services.rfcengine.RFCJCOServer.handleRequest(RFCJCOServer.java:69) at com.sap.mw.jco.JCO$Server.dispatchRequest(Unknown Source) at com.sap.mw.jco.rfc.MiddlewareRFC$Server.nativeListen(Native Method) at com.sap.mw.jco.rfc.MiddlewareRFC$Server.listen(Unknown Source) at com.sap.mw.jco.JCO$Server.listen(Unknown Source) at com.sap.mw.jco.JCO$Server.run(Unknown Source) at java.lang.Thread.run(Thread.java:513) ---" p3="" p4="">MAPPING.GENERIC</SAP:Code>
      <SAP:Text language="EN">Error during mapping</SAP:Text>
      </SAP:ErrorHeader>
    SourceTranslator is the mapping program. The UnmarshalException class is available in the archive.
    Can you please suggest that whether:
    1) JAXB related files should be available in the same archive or they should be in the Global Namespace ?
    2) Any clarifications that you may be reaching seeing the above dump?
    3) Any opinions on whether to go for JAXB, DOM, SAX for the mapping programs where IDoc's are involved?
    Doubt 2
    For the JAXB environment we exported the Target XSD for FIDCCP02 IDoc Type from the Integration Builder. The segment E1FIKPF has a MaxOccurs and MinOccurs defined as 1. Now these are the following issues:
    The IDoc segment can be replicated into the message mapping editor provided by XI. Thus, there can be multiple header level segments for E1FIKPF in a single IDoc. Then does that mean that XI does not validates the resultant OutputStream from the Mapping Program against the available XSD?
    If XI validates that against the output XSD how exactly are multiple segments allowed? I have cross checked the XSD after duplicating the segment and activating that mapping (taking the XSD from the Mapping Itself) for the multiple E1FIKPF, but,  there was only a single occurrence of that segment found and that too was with MaxOccurs, MinOccurs = 1?
    To make my JAXB libraries produce the similar output(with multiple header segments in a single IDoc) as is being done in the mapping editor, I need to modify the maxOccurs for that segment(E1FIKPF) as Unbounded. Now,
    1.     Can I somehow import this modified XSD into the XI environment ? ( I doubt that we can do that???)
    2.     If we cannot import this XSD, then with the validation occurring against this XSD how would XI take care of that?
    Doubt 3
    The XSD that is generated in XI environment refers to the namespace under which the IDoc definition was imported as a default namespace. The JAXB generated XML which is based on the XSD definition is expecting the XML to be in namespace of Integration Builder.
    But the input stream (XML) coming to the JAXB classes at the time of running is containing xmlns="atostosap" in the root element. This is the namespace name for which the code is being developed. Thus it results in Unmarhsall exception indicating the expected elements should be
    [{IB Namespace}Header_element_for_datatype].
    Any information on above would be of great help....
    Thanks in Advance
    Ashish Mittal

    Also, JAXB 2.0 Compilation with Tools>JAXB Compilation would be suitable.

  • JAXB 1.0 release date?

    According to the JAXB web site, http://java.sun.com/xml/jaxb/index.html:
    "JAXB 1.0 will be available as an optional package for the Java(TM) 2 Platform, Standard Edition (J2SE(tm)). JAXB may be included in future releases of J2SE or the Java� 2 Platform, Enterprise Edition (J2EE�)."
    Does anyone know the scheduled release date of the JAXB 1.0 optional package, or if the release date will be around the same time as the J2SE 1.4 scheduled release?
    Regards,
    Vanita

    <xml-java-binding-schema>
         <options package="my.package.com"/>
         <element name="test" type="class" root="true"/>
    </xml-java-binding-schema>

  • Error at the time of Deploying EJB  jar on JBoss

    Hi:
    I am going to create web service using EJB3.0.
    But at the time deploying file on JBOss i am getting following error:
    12:22:51,856 ERROR [AbstractKernelController] Error installing to Real: name=vfszip:/home/crayom/projects/tools/jboss-5.0.0.CR2/server/default/deploy/TempConvert.jar state=PreReal mode=Manual requiredState=Real
    org.jboss.deployers.spi.DeploymentException: Error during deploy: vfszip:/home/crayom/projects/tools/jboss-5.0.0.CR2/server/default/deploy/TempConvert.jar
         at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49)
         at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:175)
         at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1285)
         at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1003)
         at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:944)
         at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
         at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
         at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
         at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
         at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
         at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
         at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
         at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:627)
         at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:541)
         at org.jboss.system.server.profileservice.ProfileServiceBootstrap.loadProfile(ProfileServiceBootstrap.java:265)
         at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:143)
         at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:409)
         at org.jboss.Main.boot(Main.java:209)
         at org.jboss.Main$1.run(Main.java:544)
         at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
         at java.lang.String.substring(String.java:1938)
         at org.jboss.wsf.common.JavaUtils.getPackageName(JavaUtils.java:533)
         at org.jboss.ws.metadata.wsdl.WSDLUtils.getTypeNamespace(WSDLUtils.java:700)
         at org.jboss.ws.metadata.builder.jaxws.JAXWSWebServiceMetaDataBuilder.processWebService(JAXWSWebServiceMetaDataBuilder.java:313)
         at org.jboss.ws.metadata.builder.jaxws.JAXWSWebServiceMetaDataBuilder.buildWebServiceMetaData(JAXWSWebServiceMetaDataBuilder.java:107)
         at org.jboss.ws.metadata.builder.jaxws.JAXWSServerMetaDataBuilder.setupProviderOrWebService(JAXWSServerMetaDataBuilder.java:50)
         at org.jboss.ws.metadata.builder.jaxws.JAXWSMetaDataBuilderEJB3.buildMetaData(JAXWSMetaDataBuilderEJB3.java:76)
         at org.jboss.wsf.stack.jbws.UnifiedMetaDataDeploymentAspect.start(UnifiedMetaDataDeploymentAspect.java:70)
         at org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl.start(DeploymentAspectManagerImpl.java:144)
         at org.jboss.wsf.container.jboss50.BareWSFRuntime.start(BareWSFRuntime.java:66)
         at org.jboss.wsf.container.jboss50.deployer.AbstractDeployerHookEJB.deploy(AbstractDeployerHookEJB.java:48)
         at org.jboss.wsf.container.jboss50.deployer.AbstractWebServiceDeployer.internalDeploy(AbstractWebServiceDeployer.java:60)
         at org.jboss.wsf.container.jboss50.deployer.WebServiceDeployerEJB.internalDeploy(WebServiceDeployerEJB.java:115)
         at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
         at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:169)
         ... 18 more
    12:22:51,897 ERROR [ProfileServiceBootstrap] Failed to load profile: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):
    *** CONTEXTS IN ERROR: Name -> Error
    vfszip:/home/crayom/projects/tools/jboss-5.0.0.CR2/server/default/deploy/TempConvert.jar -> java.lang.StringIndexOutOfBoundsException: String index out of range: -1So, can any body tell me the solution of this problem?
    Thank You.

    AnupDesai wrote:
    Hi:
    After adding require packages also i am getting the same error.
    Well, if it's not a version problem with either the JDK (installing java 6 on top of a java 5 distribution) or the Jars (like JAXB) , then , as pointed out, you might have written your Web service using a packageless class:
    java.lang.StringIndexOutOfBoundsException: String index out of range: -1
         at java.lang.String.substring(String.java:1938)
         at org.jboss.wsf.common.JavaUtils.getPackageName(JavaUtils.java:533)Restart a new project in your IDE with a packaged ws from the start, and see if it works.

  • JAXB Demo Crashes - using JDK 1.4.2

    I have installed the pack (1.6) with JDK 1.4.2. That finished 'ok'.
    Now I am getting the error: [java] java.lang.NoSuchMethodError: javax.xml.parsers.SAXParserFactory.getSchema()Ljavax/xml/validation/Schema;
    when trying to run the bind choice jaxb demo.
    As far as I can tell the javax.xml libraries in the java jdk1.4 are too old. How will this work with jdk 1.4 ?
    Thanks.

    Just FYI -
    (This issue is also discussed in this forum, named Java Forums - JAXB JDK requirement.)
    I had a hard time trying to figure out the -D and the build file config. I am using Eclipse 3.1, so it is supposed to take care of all this for me, right?
    In Eclipse, if you click on the right side of the Run button to open it up, then from the dropdown select Run, a new window will open up that has all of your projects displayed. Select your JAXB project (which might already be highlighted) and you'll see some tabs.
    Select the Classpath tab.
    Here you'll see Bootstrap Entries. On the right you'll see an Add Jars button. Click on it.
    Add the JAXB and JAXP jar files, per the Sun specs:
    jaxb-api.jar
    jaxb-impl.jar
    jaxb-libs.jar
    jaxb-xjc.jar
    jaxp-api.jar
    dom.jar
    sax.jar
    xalan.jar
    xercesImpl.jar
    ....basically all the jars in the JAXB and JAXP lib directories, including the endorsed files, will do.
    This will take care of this issue with JAXB and the 1.4.2 issue when you use Eclipse 3.1. Hope this helps, as it took an experienced Eclipse developer to show me this...

  • JAXB vs. JAX-RPC

    Hello everyone!
    I encountered a problem while developing a web service under JWSDP 1.1 (Windows NT)
    First of all I used JAXB-1.0 to create the code taking care of my XML files. So far, so good.
    Afterwards I deployed a web service (using ant). My JAXB-code is integrated into the sever. On the (static) client, I'm calling a server method, which refers to the jar file including the JAXB-code.
    As expected, it gives me "javax.xml.bind.JAXBException: Unable to locate jaxb.properties for ..." I found this bug in the bugs database.
    So, I tried the work around "Rather than use JAXBContext.newInstance(), I make a new instance with my.package.ObjectFactory objfac = new ObjectFactory()"
    This time, I'm getting a "java.rmi.ServerException: Missing port information"
    I also tried to unpack my JAXB-code and add it to the classpath.But it didn't work out as well :(
    Does anyone have any idea, how to make it work?
    Marcin Owczarewicz

    Hello everyone!
    I encountered a problem while developing a web service
    under JWSDP 1.1 (Windows NT)
    First of all I used JAXB-1.0 to create the code taking
    care of my XML files. So far, so good.
    Afterwards I deployed a web service (using ant). My
    JAXB-code is integrated into the sever. On the
    (static) client, I'm calling a server method, which
    refers to the jar file including the JAXB-code.
    As expected, it gives me
    "javax.xml.bind.JAXBException: Unable to locate
    jaxb.properties for ..." I found this bug in the bugs
    database.
    So, I tried the work around "Rather than use
    JAXBContext.newInstance(), I make a new instance with
    my.package.ObjectFactory objfac = new ObjectFactory()"
    This time, I'm getting a "java.rmi.ServerException:
    Missing port information"
    I also tried to unpack my JAXB-code and add it to the
    classpath.But it didn't work out as well :(
    Does anyone have any idea, how to make it work?
    Marcin OwczarewiczHi Marcin,
    When you deploy your service which contains the JAXB code, please can you copy
    the jaxb.properties and bgm.ser files which were generated when you
    ran the xjc, to the jar files where you have compiled the JAXB generated code.
    Thus if you have a service which is a webapp
    you will need to first run xjc
    compile the JAXB generated code and create a jar file of these compiled classes
    copy the jaxb.properties and bgm.ser to this jar file
    copy this jar file to the WEB-INF/lib of your webapp
    Pls let me know if you have more questions,
    Thanks
    Bhakti Mehta
    Sun Microsystems.

  • Problem in build netbean projects with jaxb

    Hi, I encounter the problem which I dont' know if it is due to my pc memory insufficient or other reason.
    In my netbean projects, I add a Jaxb binding with a local xsd file, but when I try to clean and build the project, each time I have to wait for around 25 minutes, i think it is not make sense to build in such a time. As if I want to debug/run the project each time, it is impossible for me to wait like this.
    However, I have to use the xml file in that way, if I can't solve this problem, i have to write / use other method to "eat" the xml file for myself.
    Any suggestion or help is appreciated, thx.....

    Bishnu,
    Thanx for the response.
    My problem is whenever i do a little modification in the code, even if i just do some chanes & undo it then also i need to rebuild the application.
    There is a single project in my workshop which is pretty huge.As per your reply i am getting only two parts to check & uncheck i.e. If the project is "A" then i am getting A.work & project:A in the build box.
    The most important question: Do i need to shut down the server each time i make a small change?Even i have tried this by restarting the server,but every time i get the message that "the Controller.jpf could not compile."
    Any idea is most welcome.
    Samir

  • 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

  • Web Service Object Parameters and JAXB

    Hi All,
    This is my first post here and I'm hoping one of you might have encountered a similar problem before. One of our business partners provided us with a WSDL for their service, with an embedded XML schema. My job in this case is to write a message driven bean (MDB) that will take a message containing XML off of a queue and call this web service. However, their web service requires an object to be passed as input. So, I've used JAXB to generate a set of classes (from the schema I ripped out of their WSDL) that will unmarshal the XML document that comes off the queue. This works fine, however, the resulting object is an inherently different object than the object I need to pass to the web service, that one was created by auto-generating the Java proxy for the web service. Since these two classes come from the same schema definition, they have the same structure and can hold the same data, but they have different implementations. My plan is to write a method to copy the data from one object to another, but this feels redundant. Is there any approach I could use to make these two auto-generated sets of code be more compatible, other than the obvious answer of having written everything by hand? Thanks in advance for any replies.

    Are the XML instances coming from the queue and the request object to the WS defined by the same schema (from the business partner)? If they are different, there's no other option than to do a copy or some sort of XSLT (not that that's any easier though). But if the instances are defined by the same schema, just use some data binding framework that you can use for both reading the XML from the queue and that is incorporated into the WS toolkit you're using.
    For example, Axis2 allows you to use XMLBeans as a the data binding framework. Using the generated classes from Axis2, you can read in the XML instances from the queue and at the same time have the request object for the WS call.

  • Troubleshoot JAXB "chameleon schema" Errors

    I am trying to use xjc from JAXB 2.1 to generate Java code for the HL7 CDA R2 format. Unfortunately, there appears to be errors in XML Schema files and so xjc fails with this exception.
    The XML Schema files can be downloaded from http://xreg2.nist.gov/cda-validation/downloads/archives/HITSP_C37_TestPackage_03Jan_2008.zip.There are total 7 Schema files, and their names are: LabCDA.xsd, LabPOCD_MT000040.xsd, TF_Vol3_Lab.xsd, datatypes.xsd, datatypes-base.xsd, NarrativeBlock.xsd and voc.xsd. The relationship of the Schema files are complex: LabCDA.xsd is the top level Schema and includes LabPOCD_MT000040.xsd; LabPOCD_MT000040.xsd incluedes datatypes.xsd, NarrativeBlock.xsd and voc.xsd and imports TF_Vol3_Lab.xsd; TF_Vol3_Lab.xsd incluedes datatypes.xsd; datatypes.xsd incluedes datatypes-base.xsd; datatypes-base.xsd includes voc.xsd; voc.xsd includes datatypes.xsd.
    [ERROR] (Relevant to above error) another "AdxpPostBox" is generated from here.
    line 1158 of file:/F:/rcp_workspace/testCreate/processable/coreschemas/datatypes-base.xsd
    [ERROR] (Relevant to above error) This confusing error happened most likely because the schema uses a technique called "
    chameleon schema", which causes a single definition to be loaded multiple times into different namespaces. See http://fo
    rums.java.net/jive/thread.jspa?threadID=18631 for more about this.
    line 1158 of file:/F:/rcp_workspace/testCreate/processable/coreschemas/datatypes-base.xsd
    [ERROR] A class/interface with the same name "test.jaxb.labreport.cda.ADXP" is already in use. Use a class customization
    to resolve this conflict.
    line 950 of file:/F:/rcp_workspace/testCreate/processable/coreschemas/datatypes-base.xsd
    [ERROR] (Relevant to above error) another "ADXP" is generated from here.
    line 950 of file:/F:/rcp_workspace/testCreate/processable/coreschemas/datatypes-base.xsd
    [ERROR] (Relevant to above error) This confusing error happened most likely because the schema uses a technique called "
    chameleon schema", which causes a single definition to be loaded multiple times into different namespaces. See http://fo
    rums.java.net/jive/thread.jspa?threadID=18631 for more about this.
    line 950 of file:/F:/rcp_workspace/testCreate/processable/coreschemas/datatypes-base.xsd
    [ERROR] A class/interface with the same name "test.jaxb.labreport.cda.AdxpDeliveryInstallationArea" is already in use. U
    se a class customization to resolve this conflict.
    line 1123 of file:/F:/rcp_workspace/testCreate/processable/coreschemas/datatypes-base.xsd
    [ERROR] (Relevant to above error) another "AdxpDeliveryInstallationArea" is generated from here.
    line 1123 of file:/F:/rcp_workspace/testCreate/processable/coreschemas/datatypes-base.xsd
    [ERROR] (Relevant to above error) This confusing error happened most likely because the schema uses a technique called "
    chameleon schema", which causes a single definition to be loaded multiple times into different namespaces. See http://fo
    rums.java.net/jive/thread.jspa?threadID=18631 for more about this.
    line 1123 of file:/F:/rcp_workspace/testCreate/processable/coreschemas/datatypes-base.xsd
    [ERROR] A class/interface with the same name "test.jaxb.labreport.cda.EnFamily" is already in use. Use a class customiza
    tion to resolve this conflict.
    line 1288 of file:/F:/rcp_workspace/testCreate/processable/coreschemas/datatypes-base.xsd
    [ERROR] (Relevant to above error) another "EnFamily" is generated from here.
    line 1288 of file:/F:/rcp_workspace/testCreate/processable/coreschemas/datatypes-base.xsd
    [ERROR] (Relevant to above error) This confusing error happened most likely because the schema uses a technique called "
    chameleon schema", which causes a single definition to be loaded multiple times into different namespaces. See http://fo
    rums.java.net/jive/thread.jspa?threadID=18631 for more about this.
    line 1288 of file:/F:/rcp_workspace/testCreate/processable/coreschemas/datatypes-base.xsd
    [ERROR] Two declarations cause a collision in the ObjectFactory class.
    line 1048 of file:/F:/rcp_workspace/testCreate/processable/coreschemas/datatypes-base.xsd
    [ERROR] (Related to above error) This is the other declaration.
    line 1048 of file:/F:/rcp_workspace/testCreate/processable/coreschemas/datatypes-base.xsd
    [ERROR] Two declarations cause a collision in the ObjectFactory class.
    line 694 of file:/F:/rcp_workspace/testCreate/processable/coreschemas/datatypes.xsd
    I have referred http://forums.java.net/jive/thread.jspa?messageID=278619 and http://forums.java.net/jive/thread.jspa?threadID=18631, and solved id problem, but Unfortunately I don't know how to deal with the errors above.So I am looking help at here.
    Edited by: wangxf_2000 on Jul 7, 2009 10:10 PM

    JAXB has extra rules that it uses to validate the schema. I believe this is for simplicity in the code generation side. For example, you can't have a maxOccurs="unbounded" element in an "all" complex element, it must be in a "sequence".
    In this case (and hopefully all others) fixing the schema so that JAXB will accept it is not going to hurt anything. A length requirement is both a maxLength and a minLength.
    There are some rules I don't appreciate that JAXB tacks on. For example, if you import another schema into your binding schema, and don't use every type specified in the imported schema, it will balk. Why? I can't think of a good reason. It really makes it a pain in the ass to create reusable custom XML types. I have to have a different schema for every type.

  • JAXB binding list of doubles

    Hi, I have a problem in binding elements containing a list of doubles. The elements may occur many times. In the generated code, doubles from different elements are returned in the same list. Is there any way to force the creation of a new java type, so that doubles from different elements can be accesed separately?
    Example:
    XSD:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         elementFormDefault="qualified">
         <xsd:element name="main">
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element name="foo" type="foo"/>
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:complexType name="foo">
              <xsd:sequence>
                   <xsd:element name="bar" type="doubleArray" minOccurs="1" maxOccurs="unbounded"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:simpleType name="doubleArray">
              <xsd:list itemType="xsd:double"/>
         </xsd:simpleType>
    </xsd:schema>
    XML
    <?xml version="1.0" encoding="UTF-8"?>
    <main xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="forum.xsd">
         <foo>
              <bar>1 2 3</bar>
              <bar>4 5 6</bar>
              <bar>7 8 9</bar>
         </foo>
    </main>Generated code:
         * Objects of the following type(s) are allowed in the list
         * double
        java.util.List getBar();Method getBar returns a list containing all the doubles from all the bar elements, instead of returning a list of objects of type Bar, where each object at its turn contains a list of doubles.
    Thank you

    Rogier_de_Groot wrote:
    So if you wanted to generate an XML document like I wanted to do, you'd use something other then JAXB?I have no idea. I haven't ever had any use for XML-to-Java mappings like that. And I don't know what your requirements are; it seems to me like JAXB would do but you have some complaints which appear in my opinion to be non-critical. I certainly wouldn't start writing a JAXB clone just based on what you posted here. For me, if it works and removes the requirement for me to do 6 months of design and development, I'm willing to overlook a few things.

  • JAXB Unnecessary encoding of reserved XML chars?

    Hello all.
    Hopefully what I'm experiencing is a simple problem to fix. I've got an XML document that has the ampersand char encoded as such:
    When I parse this document into a JAXB object, it is getting encoded to:
    &amp;
    I can't figure out how or why or how to make this not happen. Has anyone run into this and figured out why?
    Thanks for you time and help.
    chris

    If you have a string that happens to contain XML data, and you want to treat that data as text contents of a containing XML file instead of treating it as markup, then there are two ways to do that. One is to enclose it in a CDATA section:
    <![CDATA[...your data goes here...]]>
    The other is to escape the XML markup characters: & becomes &amp;, > becomes &gt;, < becomes &lt;, ' becomes &apos;, and " becomes &quot;.
    If that wasn't what you meant, try asking a different version of the question.

Maybe you are looking for