JAXB Problem

Hi,
Using JAXB, I need to handle some XML with a structure something like this:
<root>
<parent>
<element1>A</element1>
<element2>B</element2>
<element3>C</element3>
<element3>D</element4>
</parent>
</root>
I can easily use JAXB to obtain an object representing the "parent" element, however to access the child elements of "parent", I seem to have to use the items() method on "parerent" which returns me a list, from which I can obtain an iterator to iterate through the elements. All the examples I have seen ot this then cast the child element to the appropriate type when getting it from the iterator, however, all the examples only ever seem to have one type of child element, so a cast can safely be used.
I have many different possible types of child element of "parent", so I cannot cast, because I do not know which type of element I will be dealing with.
Can anyone explain to me how this type of situation should be dealt with using JAXB?
TIA
Dave

Give all the different node classes the same base class and reference them through that. This is the first thing that comes to mind.

Similar Messages

  • JAXB Problem in Oracle9ias(9.0.3)

    Hi,
    I am getting following exception when i try to use JAXB in Oracle9ias(9.0.3).I have placed all latest JAXP and JAXB jars in j2ee\home also.
    Please help me to rectify this.
    Regds,
    Srini.
    PS:Stack trace is .....
    javax.xml.bind.JAXBException: Provider com.sun.xml.bind.ContextFactory could not be instantiated: java.lang.IncompatibleClassChangeError: Implementing class
    - with linked exception:
    [java.lang.IncompatibleClassChangeError: Implementing class]
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:118)
    at javax.xml.bind.ContextFinder.searchcontextPath(ContextFinder.java:233)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:153)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:281)
    at ezcommerce.ezjumpins._srini._ezJaxb._jspService(_ezJaxb.java:50)
    [SRC:/EzCommerce/EzJumpins/Srini/ezJaxb.jsp:4]
    at com.orionserver[Oracle9iAS (9.0.3.0.0) Containers for J2EE].http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)
    at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:317)
    at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:465)
    at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:379)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
    at oracle.security.jazn.oc4j.JAZNFilter.doFilter(JAZNFilter.java:283)
    at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:560)
    at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306)
    at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767)
    at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.AJPRequestHandler.run(AJPRequestHandler.java:148)
    at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.AJPRequestHandler.run(AJPRequestHandler.java:72)
    at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:797)
    at java.lang.Thread.run(Thread.java:479)

    Unfortunately you are in a grey area here ... by replacing jars in the OC4J/Oracle9iAS distribution you may get a working configuration but typically this is not supported by Oracle Support - they only support certified configurations. Support typically wants a vanilla distribution if there are any problems or some
    sort of backport testing done by the engineering team.
    You may have seen that some folks on the list got a JAXB replacement to work with 9iAS 9.0.2 ... if you want to explore this see:
    JAXB Problem with App Server 9.0.2
    The one issue with the above response is the jaxp jar included in the OC4J distribution is set up to work with the Oracle XML parser so replacing this will likely break other aspects of the installation despite the poster above finding that it worked in his situation.
    Lastly, bear in mind in the Oracle XDK we are now shipping early versions of JAXB and plan to have a JAXB 1.0 implementation around JavaOne in the XML kit that is distributed with OC4J. This will eliminate the need to replace jar files. See:
    http://otn.oracle.com/tech/xml/xdk/content.html
    Hope this helps.
    Mike.

  • JAXB Problem: xjc gives an error

    Hello everyone,
    I would like to use JAXB to extract various information from a class of XML documents that conform to a schema. After tweaking the schema so that I avoid namespace conflicts with xjc, I settled the namespace conflicts, but I got the following error. Even if you don't have an answer, could you give me some pointers so that I can at least begin tackling the problem?
    Thank you very much!
    Here is the output of the command I ran:
    C:\Documents and Settings\Berk Kapicioglu\Desktop>xjc -p test.jaxb ownership4ADocument.xsd.xml -d work
    parsing a schema...
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.apache.commons.launcher.ChildMain.run(ChildMain.java:269)
    Caused by: java.util.MissingResourceException: Can't find resource for bundle ja
    va.util.PropertyResourceBundle, key parser.cc.8
    at java.util.ResourceBundle.getObject(ResourceBundle.java:314)
    at java.util.ResourceBundle.getString(ResourceBundle.java:274)
    at com.sun.msv.datatype.xsd.regex.RegexParser.ex(RegexParser.java:138)
    at com.sun.msv.datatype.xsd.regex.ParserForXMLSchema.parseCharacterClass
    (ParserForXMLSchema.java:291)
    at com.sun.msv.datatype.xsd.regex.RegexParser.parseAtom(RegexParser.java
    :736)
    at com.sun.msv.datatype.xsd.regex.RegexParser.parseFactor(RegexParser.ja
    va:638)
    at com.sun.msv.datatype.xsd.regex.RegexParser.parseTerm(RegexParser.java
    :342)
    at com.sun.msv.datatype.xsd.regex.RegexParser.parseRegex(RegexParser.jav
    a:320)
    at com.sun.msv.datatype.xsd.regex.RegexParser.parse(RegexParser.java:158
    at com.sun.msv.datatype.xsd.regex.RegularExpression.setPattern(RegularEx
    pression.java:3040)
    at com.sun.msv.datatype.xsd.regex.RegularExpression.setPattern(RegularEx
    pression.java:3051)
    at com.sun.msv.datatype.xsd.regex.RegularExpression.<init>(RegularExpres
    sion.java:3017)
    at com.sun.msv.datatype.xsd.PatternFacet.compileRegExps(PatternFacet.jav
    a:79)
    at com.sun.msv.datatype.xsd.PatternFacet.<init>(PatternFacet.java:67)
    at com.sun.msv.datatype.xsd.TypeIncubator.derive(TypeIncubator.java:261)
    at com.sun.tools.xjc.reader.xmlschema.DatatypeBuilder.restrictionSimpleT
    ype(DatatypeBuilder.java:82)
    at com.sun.xml.xsom.impl.RestrictionSimpleTypeImpl.apply(RestrictionSimp
    leTypeImpl.java:66)
    at com.sun.tools.xjc.reader.xmlschema.DatatypeBuilder.build(DatatypeBuil
    der.java:65)
    at com.sun.tools.xjc.reader.xmlschema.SimpleTypeBuilder.buildPrimitiveTy
    pe(SimpleTypeBuilder.java:161)
    at com.sun.tools.xjc.reader.xmlschema.SimpleTypeBuilder.access$100(Simpl
    eTypeBuilder.java:50)
    at com.sun.tools.xjc.reader.xmlschema.SimpleTypeBuilder$Functor.checkCon
    version(SimpleTypeBuilder.java:201)
    at com.sun.tools.xjc.reader.xmlschema.SimpleTypeBuilder$Functor.restrict
    ionSimpleType(SimpleTypeBuilder.java:276)
    at com.sun.xml.xsom.impl.RestrictionSimpleTypeImpl.apply(RestrictionSimp
    leTypeImpl.java:66)
    at com.sun.tools.xjc.reader.xmlschema.SimpleTypeBuilder.build(SimpleType
    Builder.java:93)
    at com.sun.tools.xjc.reader.xmlschema.cs.DefaultClassBinder.simpleType(D
    efaultClassBinder.java:130)
    at com.sun.xml.xsom.impl.SimpleTypeImpl.apply(SimpleTypeImpl.java:89)
    at com.sun.tools.xjc.reader.xmlschema.cs.ClassSelector._bindToClass(Clas
    sSelector.java:212)
    at com.sun.tools.xjc.reader.xmlschema.cs.ClassSelector.bindToType(ClassS
    elector.java:177)
    at com.sun.tools.xjc.reader.xmlschema.TypeBuilder.elementDeclFlat(TypeBu
    ilder.java:213)
    at com.sun.tools.xjc.reader.xmlschema.FieldBuilder.elementDecl(FieldBuil
    der.java:384)
    at com.sun.xml.xsom.impl.ElementDecl.apply(ElementDecl.java:174)
    at com.sun.tools.xjc.reader.xmlschema.FieldBuilder.build(FieldBuilder.ja
    va:76)
    at com.sun.tools.xjc.reader.xmlschema.DefaultParticleBinder$Builder.part
    icle(DefaultParticleBinder.java:399)
    at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.applyRecursively(BGMBui
    lder.java:490)
    at com.sun.tools.xjc.reader.xmlschema.DefaultParticleBinder$Builder.mode
    lGroup(DefaultParticleBinder.java:462)
    at com.sun.xml.xsom.impl.ModelGroupImpl.apply(ModelGroupImpl.java:80)
    at com.sun.tools.xjc.reader.xmlschema.DefaultParticleBinder$Builder.buil
    d(DefaultParticleBinder.java:368)
    at com.sun.tools.xjc.reader.xmlschema.DefaultParticleBinder$Builder.part
    icle(DefaultParticleBinder.java:433)
    at com.sun.tools.xjc.reader.xmlschema.DefaultParticleBinder$Builder.buil
    d(DefaultParticleBinder.java:371)
    at com.sun.tools.xjc.reader.xmlschema.DefaultParticleBinder.build(Defaul
    tParticleBinder.java:70)
    at com.sun.tools.xjc.reader.xmlschema.ct.FreshComplexTypeBuilder$1.parti
    cle(FreshComplexTypeBuilder.java:48)
    at com.sun.xml.xsom.impl.ParticleImpl.apply(ParticleImpl.java:68)
    at com.sun.tools.xjc.reader.xmlschema.ct.FreshComplexTypeBuilder.build(F
    reshComplexTypeBuilder.java:35)
    at com.sun.tools.xjc.reader.xmlschema.ct.ComplexTypeFieldBuilder.build(C
    omplexTypeFieldBuilder.java:56)
    at com.sun.tools.xjc.reader.xmlschema.FieldBuilder.complexType(FieldBuil
    der.java:228)
    at com.sun.xml.xsom.impl.ComplexTypeImpl.apply(ComplexTypeImpl.java:194)
    at com.sun.tools.xjc.reader.xmlschema.FieldBuilder.build(FieldBuilder.ja
    va:76)
    at com.sun.tools.xjc.reader.xmlschema.cs.ClassSelector.build(ClassSelect
    or.java:340)
    at com.sun.tools.xjc.reader.xmlschema.cs.ClassSelector.access$000(ClassS
    elector.java:54)
    at com.sun.tools.xjc.reader.xmlschema.cs.ClassSelector$Binding.build(Cla
    ssSelector.java:107)
    at com.sun.tools.xjc.reader.xmlschema.cs.ClassSelector.executeTasks(Clas
    sSelector.java:240)
    at com.sun.tools.xjc.reader.xmlschema.BGMBuilder._build(BGMBuilder.java:
    118)
    at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.build(BGMBuilder.java:8
    0)
    at com.sun.tools.xjc.GrammarLoader.annotateXMLSchema(GrammarLoader.java:
    424)
    at com.sun.tools.xjc.GrammarLoader.load(GrammarLoader.java:130)
    at com.sun.tools.xjc.GrammarLoader.load(GrammarLoader.java:79)
    at com.sun.tools.xjc.Driver.run(Driver.java:177)
    at com.sun.tools.xjc.Driver._main(Driver.java:80)
    at com.sun.tools.xjc.Driver.access$000(Driver.java:46)
    at com.sun.tools.xjc.Driver$1.run(Driver.java:60)

    Hi,
    A similar error occur to me twice.
    One because pattern specification error (The pattern was incorrectly written)
    The other one was because I had in the directory JAVA_HOME\jre\lib\endorsed the files that come from JWSDP_HOME\jaxb\lib.
    This files (jaxb-api.jar, jaxb-impl.jar, jaxb-libs.jar, jaxb-xjc.jar) should only be in the directory where they come from JWSDP_HOME\jaxb\lib
    If you have them in the JAVA_HOME\jre\lib\endorsed directory try removing them from there.
    Hope I help you.

  • JAXB problem generating java classes

    I'm doing some integration and have received a schema from the vendor the other day. When I try to generate java classes with the jaxb compiler I get this output
    parsing a schema...
    [ERROR] Property "Value" is already defined.
      line 14 of jar:file:/C:/win32app/Java/jdk6/lib/tools.jar!/com/sun/xml/internal/xsom/impl/parser/datatypes.xsd
    [ERROR] The following location is relevant to the above error
      line 384 of file:/C:/code/sca-ecr.xsd
    Failed to parse a schema.
        <xsd:complexType name="options">
            <xsd:sequence>
                <xsd:element name="option" maxOccurs="unbounded">
                    <xsd:complexType>
                        <xsd:simpleContent>
                            <xsd:extension base="xsd:string">
    (Line 384)                  <xsd:attribute name="value" type="xsd:string"/>
                            </xsd:extension>
                        </xsd:simpleContent>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>So, googling about this I came across these to articles that almost describes my problem.
    http://weblogs.java.net/blog/kohsuke/archive/2005/05/compiling_mathm_1.html
    https://jaxb.dev.java.net/guide/Dealing_with_errors.htmlAdding the this code did not help. Downloading JAXB 2.1.4 did not help, adding the -extension parameter still same result.
            <xsd:annotation>
              <xsd:appinfo>           
                <jaxb:property name="someAttribute" />
              </xsd:appinfo>
            </xsd:annotation>      Why is jaxb failing ? Could it be that and attribute is not allowed to be called "value" ?
    Any answers will do
    regards abq

    Well, after hours of digging I found a solution which actually was right in front of me the whole time.
    This is how I edited the schema.
        <xsd:complexType name="options">
            <xsd:sequence>
                <xsd:element name="option" maxOccurs="unbounded" >
                    <xsd:complexType>
                        <xsd:simpleContent>
                            <xsd:extension base="xsd:string">
                               <xsd:attribute name="value" type="xsd:string" >
                                  <xsd:annotation><xsd:appinfo>
                                    <jaxb:property name="realValue" />
                                  </xsd:appinfo></xsd:annotation>
                                 </xsd:attribute>
                            </xsd:extension>
                        </xsd:simpleContent>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>Before, I placed the <xsd:annotation> tag efter the first line but inside the <xsd:attribute> made much better if you would like it to work.
    When marshling an @XmlRoot object will produce valid xml code. So even though that the server have a different xml schema, they will be able to talk to each other.
    abq

  • JAXB, problems trying to run a program

    Hi!
    I made a program similar to the create marshal example from the Java Web Services Tutorial. It compiled ok, but when I try:
    java Main
    I get the following error:
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    Do you know what might be causing this problem?
    Thanks!

    I've got this problem before,
    as time limited,
    I simply extract and copy the <jwsdp_home>\jaxb\lib\jaxb_api.jar to the folder containing the Main.java.

  • JAXB: Problem generating java enums

    Hi
    I'm having som problems configuring JAXB to generate type safe enums. The schema I'm using has several structures similar to this simplified example:
        <xs:element name="Car">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="CarTypeEnumInComplexType">
                        <xs:simpleType>
                            <xs:restriction base="xs:string">
                                <xs:enumeration value="Truck"/>
                                <xs:enumeration value="Jeep"/>
                                <xs:enumeration value="SUV"/>
                            </xs:restriction>
                        </xs:simpleType>
                    </xs:element>
                </xs:sequence>
            </xs:complexType>
        </xs:element>In the resulting Java code CarTypeEnumInComplexType is just generated as a String value in the Car Interface.
    What I really want is a separate Java class for "CarTypeEnumInComplexType" - with constants for each enumeration value.
    However, I do not want to change the schema - as this is maintained by another company.
    For a moment I thought I'd found the solution: By setting the global binding setting "typesafeEnumBase" to "xs:string" I made JAXB generate this kind of enumeration classes in cases like this:
    <xs:simpleType name="CarTypeEnum">
            <xs:restriction base="xs:string">
                <xs:enumeration value="Truck"/>
                <xs:enumeration value="Jeep"/>
                <xs:enumeration value="SUV"/>
            </xs:restriction>
        </xs:simpleType>However, I still can't make this work for enumerations nested within a complex type as illustrated in the first example.
    I'm new to XML schemas and JAXB - so I may be missing something obvious here...
    Is there any way to make JAXB generate an enum class for "CarTypeEnumInComplexType" in my first example without altering the schema structure?
    Vidar

    Well I couldnt really find any clear documentation to this , however with this post I was able to get going in the right direction I thought I would post the solution here.
    This assumes you have some control of your schema , it doesnt solve the problem where you cant touch the schema at all.
    So first my bindings.xjb file looks like:
    <?xml version="1.0"?>
    <jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jxb:extensionBindingPrefixes="xjc">
         <jxb:bindings schemaLocation="CMSOSS.xsd" node="/xs:schema">
              <jxb:globalBindings typesafeEnumBase ="xs:string">
                   <xjc:serializable uid="12343"/>
              </jxb:globalBindings>
              <jxb:schemaBindings>
                   <jxb:package name="com.cms.oss"/>
                   <jxb:nameXmlTransform>
                        <jxb:elementName suffix="Element"/>
                   </jxb:nameXmlTransform>
              </jxb:schemaBindings>
         </jxb:bindings>
    </jxb:bindings>
    First its necessary to have the enum type defined outside of the complex type:
    <xs:simpleType name="serviceTypeEnum">
              <xs:annotation>
                   <xs:documentation>Type of service being added (RES, BUS, FAX, POTS)</xs:documentation>
              </xs:annotation>
              <xs:restriction base="xs:string">
                   <xs:enumeration value="RES"/>
                   <xs:enumeration value="BUS"/>
                   <xs:enumeration value="FAX"/>
                   <xs:enumeration value="POTS"/>
              </xs:restriction>
         </xs:simpleType>
    Then you can use the enum in your complex type in the following manner
         <xs:element name="service">
              <xs:annotation>
                   <xs:documentation>Create a service tag for each new line of service</xs:documentation>
              </xs:annotation>
              <xs:complexType>
                   <xs:sequence>
                        <xs:element ref="phone"/>
                        <xs:element name="type" type="serviceTypeEnum">
                             <xs:annotation>
                                  <xs:documentation>Type of service being added (RES, BUS, FAX, POTS)
                                  </xs:documentation>
                             </xs:annotation>
                        </xs:element>
                        <xs:element ref="lineDevice"/>
                        <xs:element ref="LNP" minOccurs="0"/>
                        <xs:element ref="VMPIN"/>
                        <xs:element ref="location"/>
                        <xs:element name="userService" minOccurs="0" maxOccurs="unbounded"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
    Some better documentation on this would sure help ... however I dont think this solves completely the original problem...
    I would think that type safe enums should be built into the specification without all this custom binding stuff.
    R
    S

  • JAXB problems unmarshalling

    I used xjc to generate a set of elements from the schema shown below:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema targetNamespace="http://www.doc.state.nc.us/doccodes" xmlns="http://www.doc.state.nc.us/doccodes" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
         <xsd:element name="codeTable" type="CodeTable"/>
         <xsd:element name="codeRequest" type="CodeRequest"/>
         <xsd:complexType name="CodeTable">
              <xsd:sequence>
                   <xsd:element name="codename" type="xsd:string"/>
                   <xsd:element name="codes" type="Codes"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="Codes">
              <xsd:sequence>
              <xsd:element name="code" type="Code" minOccurs="1" maxOccurs="unbounded"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="Code">
              <xsd:sequence>
                        <xsd:element name="identifier" type="xsd:string"/>
                        <xsd:element name="description" type="xsd:string"/>
              </xsd:sequence>
         </xsd:complexType>
         <xsd:complexType name="CodeRequest">
              <xsd:sequence>
                   <xsd:element name="application" type="xsd:string"/>
                   <xsd:element name="token" type="xsd:string"/>
                   <xsd:element name="codename" type="xsd:string"/>
              </xsd:sequence>
         </xsd:complexType>
    </xsd:schema>
    I have successfully been able to marshall an xml file using the following code:
    jc = JAXBContext.newInstance( "nc.doc.nexus.code.jaxb.model");
    CodeTable codeTable = new CodeTable();
    Codes facilityCodes = new Codes();
    List<Code> codeList = facilityCodes.getCode();
    codeList.addAll(persistables); // where persistables is an ArrayList of Code objects
    codeTable.setCodes(facilityCodes);
    codeTable.setCodename("facilityCode");
    JAXBElement<CodeTable> codeTableElement = (new ObjectFactory()).createCodeTable(codeTable);
    Marshaller m = jc.createMarshaller();
    m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
    m.marshal(codeTableElement, System.out);
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder db;
    try {
    db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    m.marshal(codeTableElement, doc);
    return doc;
    catch (ParserConfigurationException e) {
    The marshalling works just fine, and results in the following xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns1:codeTable xmlns="http://www.doc.state.nc.us/doccodes" xmlns:ns1="http://www.doc.state.nc.us/doccodes">
    <ns1:codename>
    facilityCode </ns1:codename>
    <ns1:codes>
    <ns1:code>
    <ns1:identifier>
    X001 </ns1:identifier>
    <ns1:description>
    DHO DISTRICT 1 </ns1:description>
    </ns1:code>
    <ns1:code>
    <ns1:identifier>
    X002 </ns1:identifier>
    <ns1:description>
    DHO DISTRICT 2 </ns1:description>
    </ns1:code>
    <ns1:code>
    <ns1:identifier>
    X003 </ns1:identifier>
    <ns1:description>
    DHO DISTRICT 3 </ns1:description>
    </ns1:code>
    </ns1:codes>
    </ns1:codeTable>
    My code to unmarshall this xml document is as follows:
    JAXBContext jc;
    try {
    jc = JAXBContext.newInstance( "nc.doc.nexus.code.jaxb.model");
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    JAXBElement<CodeTable> codeTableElement =
    (JAXBElement<CodeTable>)unmarshaller.unmarshal(aDocument);
    catch (JAXBException e) {
         throw new DeserializerException(e);
    Now the problem. When I attempt to unmarshall this xml, I get the following UnmarshalException:
    unexpected element (uri:"", local:"ns1:codeTable"). Expected elements are <{http://www.doc.state.nc.us/doccodes}codeRequest>,<{http://www.doc.state.nc.us/doccodes}codeTable>
    I've made countless attempts to alter the unmarshal code in an attempt to determine if I had just coded it wrong, or whether jaxb is not able to interpret namespaces or schemas correctly. I have to assume the latter at this point. Can anybody shed any light on this?
    By the way, below is the xjc generated class CodeTable:
    // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.0-b26-ea3
    // See http://java.sun.com/xml/jaxb
    // Any modifications to this file will be lost upon recompilation of the source schema.
    // Generated on: 2007.08.22 at 10:42:51 AM EDT
    package nc.doc.nexus.code.jaxb.model;
    import javax.xml.bind.annotation.AccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlType;
    import nc.doc.nexus.code.jaxb.model.CodeTable;
    import nc.doc.nexus.code.jaxb.model.Codes;
    * <p>Java class for CodeTable complex type.
    * <p>The following schema fragment specifies the expected content contained within this class.
    * <pre>
    * <complexType name="CodeTable">
    * <complexContent>
    * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    * <sequence>
    * <element name="codename" type="{http://www.w3.org/2001/XMLSchema}string"/>
    * <element name="codes" type="{http://www.doc.state.nc.us/doccodes}Codes"/>
    * </sequence>
    * </restriction>
    * </complexContent>
    * </complexType>
    * </pre>
    @XmlAccessorType(AccessType.FIELD)
    @XmlType(name = "CodeTable", propOrder = {
    "codename",
    "codes"
    public class CodeTable {
    @XmlElement(namespace = "http://www.doc.state.nc.us/doccodes")
    protected String codename;
    @XmlElement(namespace = "http://www.doc.state.nc.us/doccodes")
    protected Codes codes;
    * Gets the value of the codename property.
    * @return
    * possible object is
    * {@link String }
    public String getCodename() {
    return codename;
    * Sets the value of the codename property.
    * @param value
    * allowed object is
    * {@link String }
    public void setCodename(String value) {
    this.codename = value;
    * Gets the value of the codes property.
    * @return
    * possible object is
    * {@link Codes }
    public Codes getCodes() {
    return codes;
    * Sets the value of the codes property.
    * @param value
    * allowed object is
    * {@link Codes }
    public void setCodes(Codes value) {
    this.codes = value;
    }

    UPDATE: I changed the unmarshal code to unmarshal a File instead of a DOM Document, and it works. This is the revelation I was hoping not to come to. I really don't want to have to serialize my Document to a file and then unmarshal that file from disk. This would not be an acceptable solution for a large J2EE application with many web services servicing 10000 clients. Does anybody know why the unmarshal method that accepts a DOM Document does not work?

  • JAXB problem with DTD file

    Hi All,
    I just started to learn JAXB and I come to a point in which I need to run xjc on a dtd file and jxs file. The problem is that is gives me an ERROR :
    "parsing a schema...
    [ERROR] The markup in the document preceding the root element must be well-forme
    d.
    line 1 of checkbook.dtd
    This is my dtd file:
    <!ELEMENT checkbook ( transactions, balance ) >
    <!ELEMENT transactions ( deposit | check | withdrawal )* >
    <!ELEMENT deposit ( date, name, amount )>
    <!ATTLIST deposit category ( salary | interest-income | other ) #IMPLIED >
    <!ELEMENT check ( date, name, amount, ( pending | void | cleared ), memo? )>
    <!ATTLIST check number CDATA #REQUIRED category ( rent | groceries | other ) #IMPLIED >
    <!ELEMENT withdrawal ( date, amount ) >
    <!ELEMENT balance (#PCDATA) >
    <!ELEMENT date (#PCDATA ) >
    <!ELEMENT name (#PCDATA) >
    <!ELEMENT amount (#PCDATA) >
    <!ELEMENT memo (#PCDATA) >
    <!ELEMENT pending EMPTY >
    <!ELEMENT void EMPTY >
    <!ELEMENT cleared EMPTY >
    What is the problem with it?
    Need your help and THANKS in advance
    A.B

    Try adding dom4j.jar (http://www.dom4j.org/) to your classpath and compiling with the -dtd switch. E.g.:
    xjc -dtd foo.dtd
    -- Ed

  • JAXB problem to manage nested complex types

    Hi!
    I've defined a XSD schema to design a folder structure. So I created a complex type which contains a sequence of 'folder' type elements.
    The folder type element includes several elements and a final one which is another 'folder' type element.
    So it is easy to model a general folder structure, no matter the depth and length.
    When I compile it with JAXB to have an OO view I catch the following error:
    Nested type Folder hides an enclosing type
    The fragment of code which caused the error is:
    * Java content class for Folder complex type.
    * <p>The following schema fragment specifies the expected content contained within this java content object. (defined at file:/C:/Progetti/folderschemaexample.xsd line 10)
    * <p>
    * <pre>
    * <complexType name="Folder">
    *   <complexContent>
    *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    *       <choice maxOccurs="unbounded" minOccurs="0">
    *         <element name="folder_name" type="{http://www.w3.org/2001/XMLSchema}string"/>
    *         <element name="security" type="{}ACL"/>
    *         <element name="folder" type="{}Folder"/>
    *       </choice>
    *     </restriction>
    *   </complexContent>
    * </complexType>
    * </pre>
    */The error is raised when JAXB tries to compile a Folder interface as inner in another Folder interface (generated.Folder.Folder).
    Is any JAXB guru able to suggest me how to exit from this situation to create succesfully a JAXB compliant schema which models this folder structure?
    TIA

    Hi!
    I've defined a XSD schema to design a folder structure. So I created a complex type which contains a sequence of 'folder' type elements.
    The folder type element includes several elements and a final one which is another 'folder' type element.
    So it is easy to model a general folder structure, no matter the depth and length.
    When I compile it with JAXB to have an OO view I catch the following error:
    Nested type Folder hides an enclosing type
    The fragment of code which caused the error is:
    * Java content class for Folder complex type.
    * <p>The following schema fragment specifies the expected content contained within this java content object. (defined at file:/C:/Progetti/folderschemaexample.xsd line 10)
    * <p>
    * <pre>
    * <complexType name="Folder">
    *   <complexContent>
    *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    *       <choice maxOccurs="unbounded" minOccurs="0">
    *         <element name="folder_name" type="{http://www.w3.org/2001/XMLSchema}string"/>
    *         <element name="security" type="{}ACL"/>
    *         <element name="folder" type="{}Folder"/>
    *       </choice>
    *     </restriction>
    *   </complexContent>
    * </complexType>
    * </pre>
    */The error is raised when JAXB tries to compile a Folder interface as inner in another Folder interface (generated.Folder.Folder).
    Is any JAXB guru able to suggest me how to exit from this situation to create succesfully a JAXB compliant schema which models this folder structure?
    TIA

  • Fetch error and jaxb problem in weblogic 12c

    Hi,
    I have a problem with running my webService in Weblogic 12c. The response of the webService is an entity which has an OneToMany relationship. After executing the service, its response could not be generated. I think there is a problem during MOXy’s unmarshalling operation of response entity (I haven’t had any problem in weblogic 11, because it don’t use MOXy ).
    What do you think about this problem and solution?
    Regards
    Edited by: Elham on May 27, 2012 12:51 AM

    Note that WebLogic 12c endorses JavaEE6.
    Look ups and how JNDI works is explained in the JavaEE6 tutorial: http://docs.oracle.com/javaee/6/tutorial/doc/gipjf.html

  • Marshaling problem in creation of xml thru JAXB

    Hi java gurus,
    I am trying to create an XML which will has the data of database using JAXB. I am able to generate JAXB classes, but its giving some error the stack trace is like this
    java.lang.NoSuchMethodError: com.sun.xml.bind.marshaller.XMLWriter.setXmlDecl(Z)V
         at org.bas.dss.common.vo.bii.impl.runtime.MarshallerImpl.createWriter(MarshallerImpl.java:223)
         at org.bas.dss.common.vo.bii.impl.runtime.MarshallerImpl.createWriter(MarshallerImpl.java:238)
         at org.bas.dss.common.vo.bii.impl.runtime.MarshallerImpl.createWriter(MarshallerImpl.java:233)
         at org.bas.dss.common.vo.bii.impl.runtime.MarshallerImpl.marshal(MarshallerImpl.java:126)
         at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:66)
         at org.bas.dss.common.dao.MetaDAO.createInstInformation(MetaDAO.java:627)
         at org.bas.core.fidownload.DownloadActionHandler.getInstInfoXMLData(DownloadActionHandler.java:163)
         at org.bas.core.fidownload.DownloadActionHandler.performPreDownloadAction(DownloadActionHandler.java:74)
         at org.bas.core.fidownload.DownloadAction.perform(DownloadAction.java:129)
         at org.bas.core.fidownload.DownloadAction.execute(DownloadAction.java:79)
    the method is like this,
    valueObject = getInstInformation (registrationId, appVersionId);
    System.out.println("MetaDAO-->valueObject:"+valueObject); //here i am gettingthe object
    context = JAXBContext.newInstance("org.bas.dss.common.vo.bii");
    System.out.println("MetaDAO-->context:"+context); //here i am getting the context
    sumissionInfoMarshaller = context.createMarshaller();
    System.out.println("MetaDAO-->sumissionInfoMarshaller:"+sumissionInfoMarshaller); //here also i am getting some object type
    sumissionInfoMarshaller.setProperty(
    Marshaller.JAXB_FORMATTED_OUTPUT,Boolean.TRUE);
    System.out.println("MetaDAO-->MetaDAO-->");
    sumissionInfoMarshaller.marshal (valueObject, streamToWrite); // the problem is coming here.
    anyone can suggest what will be the problem, and tell me how can i resolve this issue,
    thanks in advance,
    varma

    Pl post this question to SDK Forum

  • Upgrading to JAXB/JWSDP1.3 from JAXB/JWSDP 1.2 -- problems

    I am seeing 2 problems after upgrading to the JAXB found in WSDP 1.3 (from 1.2)
    We are using JAXB in a client/server style app where the server is accessed via a web interface and the client is delivered via Java Web Start (JWS). Both the server and client use JAXB-generated classes.
    We have an ant build.xml file that invokes xjc and this was working for us as expected.
    For the JWS piece, we need to sign the jars we use and for testing purposes we were self-signing them, including the jar files needed for JAXB also self-signed. This is also coordinated through an ant task.
    After replacing the jar files in our lib area with the ones from my recent download of the 1.3 version of JAXB the following happens.
    1. I am seeing compiler deprecation warnings for the generated code -- this did not happen in our use of JAXB from 1.2. For example:
    [javac] /Users/jjs/Projects/SGS-Install-Fixed/sgs/src/com/gestalt/sgs/uobdif/impl/runtime/SAXMarshaller.java:259: warning: ERR_MISSING_OBJECT in com.sun.xml.bind.marshaller.Messages has been deprecated
    [javac] Messages.format(Messages.ERR_MISSING_OBJECT), null,
    [javac] ^
    I am using Java 1.4.1 on Max OS X (I know... not supported but this doesn't seem like a platform dependency) and these warnings go away if I revert back to the JAXB jars from the 1.2 release of WSDP.
    2. These are only warnings, so my build proceeds with ant. But, when I get to the jar signing step I see:
    [signjar] Signing Jar : /Users/jjs/Projects/SGS-Install-Fixed/sgs/lib/jaxb-libs.jar
    [signjar] jarsigner: unable to sign jar: java.util.zip.ZipException: invalid entry compressed size (expected 63854 but got 19845 bytes)
    I looked at the jar file using the jar command and there are entries there:
    4038 Wed Dec 03 22:16:20 EST 2003 META-INF/MANIFEST.MF
    3303 Wed Dec 03 22:16:20 EST 2003 META-INF/SUN_MICR.RSA
    3780 Wed Dec 03 22:16:20 EST 2003 META-INF/SUN_MICR.SF
    0 Wed Dec 03 22:16:20 EST 2003 META-INF/pack.properties
    that suggest to me that perhaps the jar is now sigend by Sun and therefore can't be signed again. If I look at the corresponding jar from the JAXB/1.2, these SUN_MICR entries do not appear.
    Is this assumption correct? Can I deliver my app through web start with my apps own jars self-signed and the JAXB jars signed by Sun? I suppose I can un-jar the JAXB jars, remove the manifest material and then re-jar the files and sign those. I expect this might work.
    I am looking to share migration experiences (1.2 to 1.3) and to see what work-arounds there might be.
    Thanks
    Jim

    Replying to my own post.
    It seems that with the JWSDP 1.3 release, most (if not all) of the included jars are signed by Sun. You can NOT include jars with different signatures in the same web start application -- that's the error I get when I tried to do this.
    This means that if I want to package my jars using a self-signed certificate, I have to first un-jar all of the JAXB lib jars I want to include, get rid of the parts of the manifest that deal with signing, re-jar them and then sign all of the jars in my web start app using my own cert. More work for me, but not a show-stopper.
    I still am not sure why I am getting deprecated warnings from javac though.
    Jim

  • Problem validating xml file - jaxb

    hi people, I'm working with jaxb to generate Java source classes from the .xsd schemas that I have. I work with 17 schemas that, a priori, I can't modify. In those schemas there are a lot of types and structures that I can use when creating an .xml file. I've read other threads with the problem of namespaces but as a solution they provide a modification on the schemas. The generation of java source is ok, I've done custoization classes and no problem, but when I try to unmarshal an input xml file I get an error of validation:
    DefaultValidationEventHandler: [ERROR]: Probably namespace URI of tag "XFFile" is wrong (correct one is "http://ww........
    A possible xml file is :
    <?xml version="1.0" encoding="UTF-8" standalone="no" ?><!DOCTYPE XFFile><XFFile xmlns:rp210Elements="http://www.smpte-ra.org/schemes/434/200X/multiplex/S377M/2004" xmlns:s377mGroups="http://www.smpte-ra.org/schemes/434/200X/groups/S377M/2004" xmlns:s377mMux="http://www.smpte-ra.org/schemes/434/200X/multiplex/S377M/2004" xmlns:s377mTypes="http://www.smpte-ra.org/schemes/434/200X/types/S377M/2004" xmlns:s380mGroups="http://www.smpte-ra.org/schemes/434/200X/groups/S380M/2004" xmlns:s381mGroups="http://www.smpte-ra.org/schemes/434/200X/groups/S381M/200X" xmlns:s382mGroups="http://www.smpte-ra.org/schemes/434/200X/groups/S382M/200X" xmlns:s385mGroups="http://www.smpte-ra.org/schemes/434/200X/groups/S385M/2004" xmlns:s422mGroups="http://www.smpte-ra.org/schemes/434/200X/groups/S422M/200X" xmlns:s422mTypes="http://www.smpte-ra.org/schemes/434/200X/types/S422M/200X" xmlns:s423mGroups="http://www.smpte-ra.org/schemes/434/200X/groups/S423M/200X">
         <s380mGroups:ClipFramework rp210Elements:InstanceID="a6.67.7a.47.19.2f.4b.10.8f.ee.1e.59.6d.4c.f1.70" rp210Elements:LinkedGenerationID="0e.10.a8.9c.96.1c.4c.11.b1.fb.0a.a9.40.22.a4.e2">
              <rp210Elements:ClipCreationDateTime>
                   <rp210Elements:Year>2006</rp210Elements:Year>
                   <rp210Elements:Month>4</rp210Elements:Month>
                   <rp210Elements:Day>18</rp210Elements:Day>
                   <rp210Elements:Hour>12</rp210Elements:Hour>
                   <rp210Elements:Minute>0</rp210Elements:Minute>
                   <rp210Elements:Second>0</rp210Elements:Second>
                   <rp210Elements:mSec4>0</rp210Elements:mSec4></rp210Elements:ClipCreationDateTime>
              <rp210Elements:FrameworkExtendedTextLanguageCode>fr</rp210Elements:FrameworkExtendedTextLanguageCode>
         </s380mGroups:ClipFramework>
    </XFFile>
    I think it's ok because someone has provided it to my company but I can't validate it because it takes elements from many schemas (am I wrong and I can?)
    i can't post the schemas because of the copyrights (damn it). I'm not asking for a solution but if someone has an idea or has had a similar problema.. I'll appreciate all comments, thanks
    Jordi
    Message was edited by:
    WuWei

    In the schema root element xs:schema add namespace declaration.
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    In the XML document root element add xmlns:xsi and xsi:noNamespaceSchemaLocation attributes.
    <root_element xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file://c:/testing.xsd">

  • JAXB compiler problem in handling xsd:any and nillble = "true"

    Dear all,
    i am using jdeveloper 10.1.3.1 production release version.
    i am designing a xml schema that contain element of attribute nillable="true", for extensible, contain tag <xsd:any>.
    but i encounter 2 problem:
    1. for xml schema element with attribute nillable="true", no corresponding isNil(), setNil
    method is generated (refer to jaxb 1.0 spec. 5.7.1)
    2. cannot handle tag <xs:any> that generate incorrect java source code (cannot compile) [refer to jaxb 1.0 spec 5.9.5)
    *** i have add jaxb customization tag inside the <xs:any> tag
    ***   <xs:annotation><xs:appinfo>
    ***               <jaxb:property name="Extension"/>
    ***</xs:appinfo></xs:annotation>
    Does oracle's JAXB implementation conform to the JAXB 1.0 spec?
    Is it a known bug?
    Could anybody help me?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Refer to section
    E.2 Not Required XML Schema
    concepts
    "A JAXB implementation is not required to support the following XML Schema
    concepts for this version of the specification. A JAXB implementation may
    choose to support these features in an implementation dependent manner."
    E.2.2 Not supported while manipulating the XML
    content
    Schema component: wildcard
    (any)
    how can i know if an xml element with xsi:nil="true" (unmarshal)
    and set xsi:nil="true" for an element (marshal) ?
    According to the JAXB 1.0 specification:
    If {nillable} is "true", the methods setNil() and isNil() are
    generated.

  • 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

Maybe you are looking for