Jaxb & XML

import com.sun.xml.bind.unmarshaller.InterningXMLReader cannot resolved.
is any seperate jar file to be add.

The following is the list of JAR files that you need for JAXB.
jaxb-api.jar
jaxb-impl.jar
jaxb-libs.jar
jaxb-xjc.jar
jaxp-api.jar
relaxingDatatype.jar
xsdlib.jar
xercesImpl.jar
xmlParseAPIs.jar

Similar Messages

  • How to export string in CDATA with the jaxb xml writer?

    How to export string in CDATA with the jaxb xml writer?
    It read CDATA no problem but it is lost on write.

    Found it:
    ### THIS WORKS WITH SUN JAXB REFERENCE IMPLEMENTATION. ###
    (Not tested with any other)
    In the xsd, you must create a type for your string-like element.
    Then associate a data type converter class to this new type, which will produce CDATA tags.
    Then you must set a custom characterEscapeHandler to avoid the default xml escaping in order to preserve the previously produced CDATA tag.
    Good luck.
    -----type converter-----
    import javax.xml.bind.DatatypeConverter;
    public class ExpressionConverter {
         * Convert an expression from an XML file into an internal representation. JAXB will
         * probably have already stripped off the CDATA encapsulation. As a result, this method
         * simply invokes the JAXB type conversion for strings but does not take any other action.
         * @param text an XML-compliant expression
         * @return a pure string expression
         public static String parse(String text) {
              String result = DatatypeConverter.parseString(text);
              return result;
         * Convert an expression from its internal representation to an XML-compliant version.
         * This method will simply surround the string in a CDATA block and return the result.
         * @param text a pure string expression
         * @return the expression encapsulated within a CDATA block
         public static String print(String text) {
              StringBuffer sb = new StringBuffer(text.length() + 20); //should add the length of the CDATA tags + 8 EOLs to be safe
              sb.append("<![CDATA[");
              sb.append(wrapLines(text, 80));
              sb.append("]]>");
              return DatatypeConverter.printString(sb.toString());
         * Provides line-wrapping for long text strings. EOL indicators are inserted at
         * word boundaries once a specified line-length has been exceeded.
         * @param text the string to be wrapped
         * @param lineLength the maximum number of characters that should be included in a single line
         * @return the new string with appropriate EOL insertions
         private static String wrapLines(String text, int lineLength) {
              //wrap logic, watchout for quoted strings!!!!
              return text;
    ------in caller----
    Marshaller writer = ......
    writer.setProperty("com.sun.xml.bind.characterEscapeHandler", new NoCharacterEscapeHandler());
    -----escaper-----
    import java.io.IOException;
    import java.io.Writer;
    import com.sun.xml.bind.marshaller.CharacterEscapeHandler;
    public class NoCharacterEscapeHandler implements CharacterEscapeHandler {
         * Escape characters inside the buffer and send the output to the writer.
         * @param buf buffer of characters to be encoded
         * @param start the index position of the first character that should be encoded
         * @param len the number of characters that should be encoded
         * @param isAttValue true, if the buffer represents an XML tag attribute
         * @param out the output stream
         * @throws IOException if the writing process fails
         public void escape(char[] buf, int start, int len, boolean isAttValue, Writer out) throws IOException {
              for (int i = start; i < start + len; i++) {
                   char ch = buf;
                   if (isAttValue) {
                        // isAttValue is set to true when the marshaller is processing
                        // attribute values. Inside attribute values, there are more
                        // things you need to escape, usually.
                        if (ch == '&') {
                             out.write("&");
                        } else if (ch == '>') {
                             out.write(">");
                        } else if (ch == '<') {
                             out.write("<");
                        } else if (ch == '"') {
                             out.write(""");
                        } else if (ch == '\'') {
                             out.write("&apos;");
                        } else if (ch > 0x7F) {
                             // escape everything above ASCII to &#xXXXX;
                             out.write("&#x");
                             out.write(Integer.toHexString(ch));
                             out.write(";");
                        } else {
                             out.write(ch);
                   } else {
                        out.write(ch);
              return;

  • JAXB XML Unmarshalling validation problem

    Hello,
    I'm using toplink JAXB to map XML document to an object hierarchy. The set of objects was built using Toplink workbench from the corresponding XSD file. The XSD file is specified in <toplink:resource> element using an absolute path. If I use unmarshaller validation (Unmarshaller u = jc.createUnmarshaller(); u.setValidating(true)) it works fine in embedded oc4j, but fails withan UnmarshalException "An internal error condition occurred" for Line N 1.
    It looks like the cause of the exception is that toplink cannot find the XSD file. I've tried to put the XSD file into META-INF and into classes directly, and specify the relative path, but it has failed event locally in the embedded oc4j.
    Everything works if I do not turn the validation on.
    Has anybody gotten the same issue? What could be a solution if we have to perform the validation?
    Thanks
    Kate

    Hello Kate,
    One possible work around would be use the TopLink OXM specific APIs for this unmarshal. For the most part they mirror the JAXB APIs so there usage is pretty straight forward.
    XMLContext xmlContext = new XMLContext(YOUR_JAXB_CONTEXT_PATH);
    xmlUnmarshaller = xmlContext.createUnmarshaller();One API that we offer that is not part of the standard JAXB Unmarshaller is the ability to specify an EntityResolver. This class allows you to override where the XML Schema is loaded from.
    EntityResolver entityResolver = new YourEntityResolver();
    xmlUmarshaller.setEntityResolver(entityResolver);YourEntityResolver must implement org.xml.sax.EntityResolver. There is one method on this interface that returns an InputSource representing the XML Schema. You can implement this method to load the Schema from a ClassLoader.
    -Blaise

  • JAXB XML Max Siz

    Hello All:
    I am using JAXB to reading (unmarshall) a XML feed which
    is about 4GB of siz. The JAXB seems
    can not doing its job. Any one knows how to solve this problem?
    ps: does JAXB has a limitation over XML feed size?
    Many Thanks!

    Seems? Your first step is to find out what is happening and what is not happening and why. It seems likely that you are running out of memory, but if that happened normally you would get an exception and a stack trace.

  • JAXB XML parsing pbm

    Hi,
    I am generating XML using JAXB,the problem which i am facing is the XMLis not getting parsed due to namespace prefix pbm.
    The JAXB 'ns1' namespace definition:
    xmlns:ns1="http://www.mx.com/Schemas/2002/Service"
    Can be this behavior disabled somehow?
    Thanks,
    kumarsj

    The jaxb.properties file should be in the jar with your generated classes.
    For example, your generated class jar file should look like this:
    com\mycompany\myappl\...mygeneratedclassfiles...
    com\mycompany\myappl\impl\...mygeneratedclassimplfiles...
    com\mycompany\myappl\jaxb.properties

  • JAXB XML doesn't build default/fixed values?

    Hi people.
    I need to build a status XML that must look like this:
    <rule name="TeamPayment" result="Auditing">
       <code>968</code>
       <code>571</code>
    </rule>I'm using JAXB 2, there is a attribute named 'result' with a fixed value that the marshaller doesn't adds to the XML.
    I'm not setting the value of attribute 'result' in my code, because it has a fixed value and I think the marshaller must obey the Schema definition.
    Also, I set the Schema to the marshaller. marsh.setSchema(ruleSchema); This is the Schema:
    <xsd:complexType name="RuleInstance" abstract="true">
       <xsd:sequence>
          <xsd:element name="errorCode" type="xsd:string" minOccurs="0"
                maxOccurs="unbounded"/>
          <xsd:element name="scriptText" type="xsd:string" minOccurs="0"
                maxOccurs="1"/>
       </xsd:sequence>
       <xsd:attribute name="name" type="xsd:string" use="required"/>
    </xsd:complexType>
    <xsd:complexType name="AuditingRuleInstance">
       <xsd:complexContent>
          <xsd:extension base="tns:RuleInstance">
             <xsd:attribute name="result" type="xsd:string" fixed="Auditing"/>
          </xsd:extension>
       </xsd:complexContent>
    </xsd:complexType>
    <xsd:complexType name="ApprovedRuleInstance">
       <xsd:complexContent>
          <xsd:extension base="tns:RuleInstance">
             <xsd:attribute name="result" type="xsd:string" fixed="Approved"/>
          </xsd:extension>
       </xsd:complexContent>
    </xsd:complexType>
    <xsd:complexType name="DeniedRuleInstance">
       <xsd:complexContent>
          <xsd:extension base="tns:RuleInstance">
             <xsd:attribute name="result" type="xsd:string" fixed="Denied"/>
          </xsd:extension>
       </xsd:complexContent>
    </xsd:complexType>
    <xsd:complexType name="IgnoredRuleInstance">
       <xsd:complexContent>
          <xsd:extension base="tns:RuleInstance">
             <xsd:attribute name="result" type="xsd:string" fixed="Ignored"/>
          </xsd:extension>
       </xsd:complexContent>
    </xsd:complexType>
    <xsd:complexType name="DeferredRuleInstance">
       <xsd:complexContent>
          <xsd:extension base="tns:RuleInstance">
             <xsd:attribute name="result" type="xsd:string" fixed="Deferred"/>
          </xsd:extension>
       </xsd:complexContent>
    </xsd:complexType>
    <xsd:element name="rule" type="tns:RuleInstance"/>Am I doing something wrong?
    Att,
    TJ.

    I'm not so good at cmake, but I believe that you'll need to explicitely set OpenCV_ROOT_DIR in the PKGBUILD. /usr is defined in cmake/modules/FindOpenCV.cmake, but cmake seems to be missing it.

  • JAXB / XML Project with Multiple Schemas

    So, I am wondering how I can accomplish the following:
    1) I am using Toplink 10.1.3.1.
    2) I have a project that deals with many varieties of XML files.
    3) Each XML file will have its own xsd.
    4) I want to be able to generate the JAXB objects for each file type into different packages.
    5) I want to be able to create a jaxb object based on the package name. Can I just add the different projects to the session.xml file? If so, how?
    I know that you can do this with other JAXB implementations. Just curious what the deal is with Toplink? Seems that I can only have one schema per project. I then can only have one session.xml file. Using the JAXBConext to create a new instance, I am not allowed to specify an additional session.xml file.
    Thoughts? Opinions? Suggestions!!!
    Thanks,
    BradW

    Ok. Looks like I need to create a session.xml file that has multiple sessions based on the package name. Yeah!
    Now everyone knows... :)
    BradW

  • JAXB XML output as SOAP Body

    Hey,
    I currently have a psuedo webservice that pulls a string out of an http request and returns a corresponding xml document (based on a schema) to the caller. Pretty basic and it works fine. I use JAXB for the Marshalling of my objects to xml, based on the schema, so I know that my xml document is correct (well-formed and valid).
    Now, I would like to do the same thing, except as a SOAP-RPC call. I figure, for the service side, I can just wrap what I already generate in a SOAP Envelope, in response to a SOAP request. Creating the client is easy but I am having trouble with the client side. How can I simply pass an xml document as the SOAP body using Axis/JAX-RPC or whatever, instead of re-mapping to Java object, which might not guarantee the response document conforms to my schema?
    I've looked at SAAJ for this a bit, but this seems more about sending a message to a service rather than creating a response from a service....
    Any ideas?
    Mike

    Yes, it's been ten months, but have you figured out how to integrate SOAP and JAXB? I am attempting to make my SOAP client application code easy for a Java beginner to understand, so JAXB would be ideal.

  • Jaxb & XML & encoding problem                      *URGENT*

    Hello,
    ***Do not be scared because of the length of the question please. I tried to explain problem clearly.***
    I am developing a Web service for a particular client. The client has provided .wsdl and some .xsd files for me.
    I used JWSDP-2.0 to generate holder classes from those .xsd files. In order to specify the root elemnen, I added "@XmlRootElement" annotation in front of the ServiceInfo class (, and also imported "javax.xml.bind.annotation.XmlRootElement"). I am using Eclipse in this project.
    I prepared the Web service exactly as specified by the client, but when I test it with the client the client application cannot show the XML data that it receives as a response to its request. The client application opens a file, writes the XML response to that file and also shows the response on the client application window. However, that file is always empty and I see nothing on the client application window. I do not have the client application's source code, but I do know that client application has no bug.
    NOTE: I have a guideline for developing the Web Service for this particular client and it says there: "ServiceInfo is transfered as a Unicode string, and then encoded as UTF-16."
    (Actually I don't know whether this is the reason of my problem but it is still sth that should be known I guess.)
    Here is the code of my method:
    public java.lang.String getServiceInfo() throws java.rmi.RemoteException {
    JAXBContext servInfoContext = JAXBContext.newInstance("com.gw.oms.serviceinfo"); //com.gw.oms.serviceinfo is the directory where all generated java (from serviceinfo.xsd file) files are stored.
    // create an ObjectFactory instance, create instances of holder classes
    // (root element is "serviceInfo") and set their values.
              try {
                   StringWriter writer = new StringWriter();
                   Marshaller marshaller = servInfoContext.createMarshaller();
                   marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-16");
                   marshaller.marshal(serviceInfo, writer);
                   return writer.toString();
              } catch (JAXBException e) {
                   throw new RemoteException("Error marshalling serviceInfo", e);
    I guess the code piece in the try-catch block is true, but maybe I am continuously missing sth. Can you see any wrong thing in the code?
    In order to see what is happenning in the communication between my Web Service and the client application I analyzed the traffic between them via Ethereal network sniffing tool. Here is some info:
    FROM CLIENT TO WEB SERVICE: (Data Content of HTTP packet)
    <?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope
    xmlns:soap="http://schema.xmlsoap.org/soap/envelope"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
    <GetServiceInfo
    xmlns="http://....XXX....."/>
    </soap:Body>
    </soap:Envelope>
    FROM WEB SERVICE TO CLIENT: (Data Content of HTTP packet)
    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope
    xmlns:soap="http://schema.xmlsoap.org/soap/envelope"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
    <GetServiceInfoResult
    xmlns=""/> **>> WARNING 1 <<**
    <?xml version="1.0" encoding="UTF-16" standalone="yes"?>\n<serviceInfo xmlns="http://....XXX..../serviceInfo"><serviceProvider>Service Provider Name< **>> WARNING 2 <<**
    </GetServiceInfoResult>
    </soapenv:Body>
    </soapenv:Envelope>
    **>> WARNING 1 <<**: WHY IS 'XMLNS' EMPTY HERE??? SHOULDN'T IT BE "http://....XXX....." ALSO????
    **>> WARNING 2 <<**: WHY DON'T I SEE THE COMPLETE SERVICEINFO HERE? ONLY 1 HTTP RESPONSE PACKET IS BEING SENT TO THE CLIENT BY MY WEB SERVICE.
    If I make Eclipse write to the console what I am sending, I see the result below:
    <?xml version="1.0" encoding="UTF-16"?>
    <serviceInfo xmlns="http://....XXX...../serviceInfo">
    <serviceProvider>MY UNIVERSITY</serviceProvider>
    <serviceUri>http://myserviceuri.com</serviceUri>
    <signUpPage>http://signupmyservice/services/ITUServiceSoap</signUpPage>
    <targetLocale>1053</targetLocale>
    <localName>MIN SERVIS</localName>
    <englishName>MY SERVICE</englishName>
    <authenticationType>other</authenticationType>
    <supportedService>
    <SMS_SENDER maxSbcsPerMessage="160" maxRecipientsPerMessage="400" maxMessagesPerSend="5" maxDbcsPerMessage="0"/>
    </supportedService>
    </serviceInfo>
    Somehow the client application cannot receive (or validate) the serviceinfo that my Web service sends. I suspect that sth is wrong with my Java code. Can any one see any error in this schema?
    I am really stucked. Any recommendation would be very valuable for me.
    Thanks & Regards

    I feel like nobody is following this forum anymore.. :)
    Does anybody have any idea...?
    Regards

  • JAXB - xml schema problems

    Hi, I'm having problems constructing a correct schema for my XML input. I already have this XML:
    <resultSet>
    <row id="1">
      <col name="ID">1</col>
      <col name="parentID">0</col>
      <col name="categoryName">Brands</col>
    </row>
    <row id="2">
      <col name="ID">2</col>
      <col name="parentID">0</col>
      <col name="categoryName">Laerdal</col>
    </row>
    (...) etc. for 244 rows
    </resultSet>I've looked at the examples to try to figgure out how the schema (XSD) should look like, but I keep getting rumtime exceptions. Here's my XSD so far:
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="resultSet" type="CategoryType"/>
    <xsd:complexType name="CategoryType">
         <xsd:sequence>
         <xsd:element name="row" type="CategoryRow"/>
         </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="CategoryRow">
         <xsd:sequence>
              <xsd:element name="col" type="CategoryCol"/>
         </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="CategoryCol">
         <xsd:sequence>
              <xsd:element name="ID" type="xsd:int"/>
              <xsd:element name="parentID" type="xsd:int"/>
              <xsd:element name="categoryName" type="xsd:string"/>
         </xsd:sequence>
    </xsd:complexType>
    </xsd:schema>I can't find any examples on converting XML to a schema that would define it.
    Help anyone??
    by the way, this is the runtime exception I get:
    DefaultValidationEventHandler: [ERROR]: Unexpected end of element {}:col
    javax.xml.bind.UnmarshalException: Unexpected end of element {}:col
         at com.sun.xml.bind.unmarshaller.UnreportedException.createUnmarshalException(UnreportedException.java:59)
         at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.reportAndThrow(SAXUnmarshallerHandlerImpl.java:406)
         at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.endElement(SAXUnmarshallerHandlerImpl.java:108)
         at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1528)
         at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)
         at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)
         at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)
         at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)
         at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:500)
         at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
         at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
         at com.sun.xml.bind.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:139)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:129)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:134)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:138)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:151)
         at no.xait.dod.communication.dataAccess.sendXML(dataAccess.java:121)
         at no.xait.dod.designondemand.<init>(designondemand.java:87)
         at no.xait.dod.designondemand.main(designondemand.java:602)
    Process terminated with exit code 0

    Modified schema:
    <xsd:element name="resultSet">
    <xsd:complexType>
    <xsd:sequence>     
    <xsd:element ref="row" minOccurs="0" maxOccurs="unbounded"//>     
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="row">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element ref="col" minOccurs="0" maxOccurs="unbounded"//>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="col">
    <xsd:complexType>
    <xsd:sequence>          
    <xsd:element name="ID" type="xsd:int"/>     
    <xsd:element name="parentID" type="xsd:int"/>          
    <xsd:element name="categoryName" type="xsd:string"/>     
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>

  • NullPointerException in JAXB

    Hi all,
    I have a problem with JAXB. I installed the jwsdp-1_6-windows-i586.exe,
    and made some test running the xjc using the command line. It works fine,
    all Classes has been created and compiled. Furthermore I wanted to use it
    within eclipse. I created a new Project, copied all needed libs into it,
    but I got a NPE:
    E:\eclipse>E:\java\j2sdk1.4.2_04\bin\java -Djava.endorsed.dirs=E:\workspace\_internTestJAXB\lib;E:\workspace\_internTestJAXB\lib\endorsed -jar E:\workspace\_internTestJAXB\lib\jaxb-xjc.jar E:\workspace\_internTestJAXB\xsd\faa.xsd -p de.jaxb.bo -d E:\workspace\_internTestJAXB\src\
    parsing a schema...
    compiling a schema...
    Exception in thread "main" java.lang.NullPointerException
    at com.sun.tools.xjc.generator.SkeletonGenerator.generateStaticRuntime(SkeletonGenerator.java:238)
    at com.sun.tools.xjc.generator.SkeletonGenerator.<init>(SkeletonGenerator.java:130)
    at com.sun.tools.xjc.generator.SkeletonGenerator.generate(SkeletonGenerator.java:110)
    at com.sun.tools.xjc.Driver.generateCode(Driver.java:379)
    at com.sun.tools.xjc.Driver.run(Driver.java:220)
    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)
    Someone an idea what's wrong?
    Thanks in advance,
    zzkozak

    It looks like a build path problem with your Eclipse project. Why not try an Ant script such as the following? It's much easier than using xjc from the command line.
    <?xml version="1.0" standalone="yes"?>
    <project name="DataExtract JAXB Build" basedir="." default="run">
         <description>
              Controls the JAXB XML schema and Java compilations and wraps the results into a JAR file.
        </description>
         <!-- Change this property to point to the JWSDP installation directory on your machine.  -->
         <property name="jwsdp.home" value="C:\Program Files\Java\jwsdp-1.6" />
         <path id="classpath">
              <pathelement path="src" />
              <fileset dir="${jwsdp.home}" includes="jaxb/lib/*.jar" />
              <fileset dir="${jwsdp.home}" includes="jwsdp-shared/lib/*.jar" />
              <fileset dir="${jwsdp.home}" includes="jaxp/lib/**/*.jar" />
         </path>
         <taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
              <classpath refid="classpath" />
         </taskdef>
         <target name="run" description="Compile the XML schemas and all the Java source files they create.">
              <echo message="Compiling the Schema..." />
              <mkdir dir="tmpClasses" />
              <mkdir dir="tmpSource"/>
              <echo message="Doing forum.xsd..." />
              <xjc schema="forum.xsd" package="extract" target="tmpSource" />
              <echo message="Compiling the java source files..." />
              <javac srcdir="tmpSource" destdir="tmpClasses" debug="on" >
                   <classpath refid="classpath" />
              </javac>
              <echo message="Bundling the generated classes and source files into forum.jar"/>
              <jar destfile="forum.jar" update="true">
                   <fileset dir="tmpClasses"/>     
                   <fileset dir="tmpSource"/>
              </jar>
              <echo message="Cleaning up the working directories."/>          
              <delete dir="tmpClasses"/>
              <delete dir ="tmpSource"/>
         </target>
    </project>Copy this script into a file called build.xml within your Eclipse project. Change the value of jwsdp.home to the location of your JWSDP installation, and change the name of the Schema. With the script and the Schema in the same directory, right-click on the file and select Run As -> Ant Build.
    This script bundles the generated classes into a jar file and and then deletes the source. But, you can play around with it if you want to do something else.

  • JAXB, @XmlType(propOrder = { ... }) and @XmlAttribute

    Hi.
    Preamble: we are working with governmental authority, and we are using XML-files for information transfer.
    They (authority) support only strict elements and attributes order in files (not only for elements but also for attributes!). :(
    Now we are using manual assembly of XML-file.
    I found this JAXB example: http://www.vogella.com/articles/JAXB/article.html
    Here I found "@XmlType(propOrder = { "field2", "field1",.. })".
    I tried this and get first results - elements were in order that I specify.
    When I annotated 4 of 8 fields with @XmlAttribute, it also works fine, but I should inverse the order of attributes in propOrder - it's ok.
    It looks like I can use JAXB for my task.
    I use Java SE 1.6.0_35.
    Question is:
    Will this behaviour be as is in further releases of Java SE? In 1.7, 1.8 and so on.
    Test code:
    package com.mycompany.test8_jaxb_with_ordering;
    import javax.xml.bind.annotation.XmlAttribute;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlType;
    @XmlRootElement(name = "TestClass")
    @XmlType(propOrder = { "test2", "test3", "test4", "test1", "test5", "test7", "test6", "test8" })
    public class TestClass {
    private String test1 = "test1&_text";
    private String test3 = "test3\"_text";
    private String test2 = "test2_text";
    private String test4 = "test4_text";
    private String test5 = "test5&_text";
    private String test7 = "test7\"_text";
    private String test6 = "test6_text";
    private String test8 = "test8_text";
    @XmlAttribute
    public String getTest1() {
    return test1;
    @XmlAttribute
    public String getTest2() {
    return test2;
    @XmlAttribute
    public String getTest3() {
    return test3;
    @XmlAttribute
    public String getTest4() {
    return test4;
    public String getTest5() {
    return test5;
    public String getTest6() {
    return test6;
    public String getTest7() {
    return test7;
    public String getTest8() {
    return test8;
    public void setTest1(String test1) {
    this.test1 = test1;
    public void setTest2(String test2) {
    this.test2 = test2;
    public void setTest3(String test3) {
    this.test3 = test3;
    public void setTest4(String test4) {
    this.test4 = test4;
    public void setTest5(String test5) {
    this.test5 = test5;
    public void setTest6(String test6) {
    this.test6 = test6;
    public void setTest7(String test7) {
    this.test7 = test7;
    public void setTest8(String test8) {
    this.test8 = test8;
    package com.mycompany.test8_jaxb_with_ordering;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.Writer;
    import javax.xml.bind.*;
    public class App {
    private static final String TEST_XML = "./test-jaxb.xml";
    public static void main(String[] args) throws PropertyException, JAXBException, IOException {
    TestClass tc = new TestClass();
    JAXBContext context = JAXBContext.newInstance(TestClass.class);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.marshal(tc, System.out);
    Writer w = null;
    try {
    w = new FileWriter(TEST_XML);
    m.marshal(tc, w);
    } finally {
    try {
    w.close();
    } catch (Exception e) {
    // get variables from our xml file, created before
    System.out.println();
    System.out.println("Output from our XML File: ");
    Unmarshaller um = context.createUnmarshaller();
    TestClass tc2 = (TestClass) um.unmarshal(new FileReader(TEST_XML));
    System.out.println("tc2.test1 = "+tc2.getTest1());
    System.out.println("tc2.test2 = "+tc2.getTest2());
    System.out.println("tc2.test3 = "+tc2.getTest3());
    System.out.println("tc2.test4 = "+tc2.getTest4());
    System.out.println("tc2.test5 = "+tc2.getTest5());
    System.out.println("tc2.test6 = "+tc2.getTest6());
    System.out.println("tc2.test7 = "+tc2.getTest7());
    System.out.println("tc2.test8 = "+tc2.getTest8());
    -----

    Hello,
    @XmlType is only for elements.
    We cannot use attributes with it.
    Thanks

  • Is JaxB the correct tool for what I want

    (New to JaxB/XML, but good with Java)
    I'm using an XML document to hold information about classes. Currently I'm using JaxB and it seems to work ok, but I just had one consern. It would be nice (both faster and less mem) if I could read the XML information into the classes I was using in my program directly. Right now with JaxB, I am reading them into some generated classes and retrieving that information from those classes and putting it into my main classes. What I would like to do is while information for classes is being read in, don't create more memory for them to be stored into, instead store it directly into the main classes. I'm thinking this would be faster. Any ideas? Should I stick with JaxB or is something else better suited for what I want. As an example, my program reads in a List[] Float, but what I really need is a float[] (Yes I know how to convert, but it'ld be nice to start with the float[]) As another example, I read in 3 floats right now as Float[] but what I really need is a class called Vector3f() I'm using, derived from those 3 floats. It would be nice to give me that Vector3f directly instead of making a Float[] and me having to make a Vector3f

    That's List Float up there, not List[] Float :)

  • All I want to do is CRUD an Object to a Database

    I don't need security or transactions or XML marshalling or caching. I just want to CRUD!
    First I started with simple JDBC. Tables of tables of tables. Very tedious.
    Then I tried JAXB->XML->Oracle XML DB. A little bleeding edge. Vendor specific solution makes me cry.
    Then I found PERSISTENCE. Problems solved, right?
    Well, after a week of hell trying to get Netbeans/JAXB/Glassfish/Hibernate to play nicely, I find out:
    1) Each entity needs it's own primary key, GLOBALLY unique to all entities of its type (not just unique within the main entity I'm persisting). Why can't I just reference each "sub-entity" based upon the "main entity's" primary key and the sub-entity's "local" primary key?
    2) Tracking hibernate SQL errors is like pulling teeth. A single "RollbackException" with no SQL error tells me nothing!
    3) The seemingly intuitive EntityManager class has methods that aren't behaving intuitively. Using an EntityManager. EM.contain does not tell me whether the db contains an entity (why can't I use this method with a primary key instead of a whole object?) EM.merge does not update a collection ob "sub-entity's", it just adds any new ones it finds. Etc.
    Can EJB3 help me? I'm about to go back to JDBC because I'm getting frustrated that such a simple ORM solution seems out of my grasp!

    EJB3 JPA has the problems you described.
    Maybe RIFE CRUD could solve your problem:
    https://rife-crud.dev.java.net/

  • WSDL for web method with parameters from different namespaces

    I'm trying to create a web service that exposes a method that accepts a JAXB XML object and a timestamp as parameters and returns another JAXB XML object. I've tried to follow the contract-first method by creating the schema and WSDLs first. I've created the schemas for the XML and deployed them on a web server and I've written the following WSDL:
    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
         xmlns:tns="http://bar.org"
         xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="MyWebService"
         xmlns:ns0="http://foo.org/Transaction"
         xmlns:ns1="http://bar.org/TransactionResponse"
         targetNamespace="http://bar.org">
         <!-- T Y P E S -->
         <wsdl:types>
              <xsd:schema targetNamespace="http://bar.org"
                  xmlns:ns0="http://foo.org/Transaction"
                  xmlns:ns1="http://bar.org/TransactionResponse"
                  xmlns="http://bar.org">
                   <xsd:import namespace="http://foo.org/Transaction" schemaLocation="http://myHost/schemas/Transaction.xsd"/>
                   <xsd:import namespace="http://bar.org/TransactionResponse" schemaLocation="http://myHost/schemas/TransactionResponse.xsd"/>
                   <xsd:element name="ProcessTransactionRequest">
                       <xsd:complexType>
                           <xsd:sequence>
                               <xsd:element ref="ns0:Transaction"/>
                               <xsd:element name="TransactionTime" type="xsd:dateTime"/>
                           </xsd:sequence>
                       </xsd:complexType>
                   </xsd:element>
              </xsd:schema>
         </wsdl:types>
         <!-- M E S S A G E S -->
         <wsdl:message name="ProcessTransactionRequest">
              <wsdl:part element="tns:ProcessTransactionRequest" name="parameters" />
         </wsdl:message>
         <wsdl:message name="ProcessTransactionResponse">
              <wsdl:part element="ns1:TransactionResponse" name="parameters" />
         </wsdl:message>
         <!-- P O R T   T Y P E -->
         <wsdl:portType name="MyWebServicePortType">
              <wsdl:operation name="ProcessTransaction">
                   <wsdl:input message="tns:ProcessTransactionRequest" />
                   <wsdl:output message="tns:ProcessTransactionResponse" />
              </wsdl:operation>
         </wsdl:portType>
         <!-- B I N D I N G -->
         <wsdl:binding name="MyWebServiceSOAP" type="tns:MyWebServicePortType">
              <soap:binding style="document"
                   transport="http://schemas.xmlsoap.org/soap/http" />
              <wsdl:operation name="ProcessTransaction">
                   <soap:operation soapAction=""/>
                   <wsdl:input>
                        <soap:body use="literal"/>
                   </wsdl:input>
                   <wsdl:output>
                        <soap:body use="literal"/>
                   </wsdl:output>
              </wsdl:operation>
         </wsdl:binding>
         <!-- S E R V I C E -->
         <wsdl:service name="MyWebService">
              <wsdl:port binding="tns:MyWebServiceSOAP" name="MyWebServiceSOAP">
                   <soap:address location="http://www.example.org/"/>
              </wsdl:port>
         </wsdl:service>
    </wsdl:definitions>However when I run the WsImport tool bundled with JAX-WS RI 2.1.1, I get the following interface:
    public interface MyWebServicePortType {
         * @param parameters
         * @return
         *     returns org.bar.transactionresponse.TransactionResponse
        @WebMethod(operationName = "ProcessTransaction")
        @WebResult(name = "TransactionResponse", targetNamespace = "http://bar.org/TransactionResponse", partName = "parameters")
        public TransactionResponse processTransaction(
            @WebParam(name = "ProcessTransactionRequest", targetNamespace = "http://bar.org", partName = "parameters")
            ProcessTransactionRequest parameters);
    }Which is workable, but I was wondering how to modify the WSDL to get a web method signature similar to:
    public TransactionResponse processTransaction(
            @WebParam(name = "Transaction", targetNamespace = "http://foo.org/Transaction", partName = "transaction")
            Transaction transaction,
            @WebParam(name = "TransactionTime", targetNamespace = "http://bar.org", partName = "transactionTime")
            XMLGregorianCalendar transactionTime);With two parameters in the parameter list instead of one. Is there a way to do this?

    Try changing the <xsd:element name="ProcessTransactionRequest"> element name to: <xsd:element name="ProcessTransaction"> and update the reference to it in the <wsdl:message name="ProcessTransactionRequest"> message.
    In order to use wrapper style, your WSDL needs to have the following characteristics:
    1) The operation's input and output messages (if present) each contain a single part
    2) The input message part refers to a global element declaration whose localname is equal to the operation name
    3) The output message refers to a global element declaration
    4) The elements referred to by the input and output message parts (henceforth referred to as wrapper elements) are both complex types defined using the xsd:sequence compositor
    5 The wrapper elements only contain child elements, they must not contain other structures such as wildcards...

Maybe you are looking for

  • Satellite L770 - ethernet adapter has stopped working

    HI I have three laptops all connectable to my home hub, but I seem to be having serious problems with the latest model, the L770-13D. The signal strength has never been as good as the older models and just recently the Ethernet adapter has stopped wo

  • I want to repair my iPod Hard drive

    The 20GB hard drive of my 4G-iPod is not working. Do you know how to change it? And how to purchase a new hard drive? Or maybe you know a place in Germany that can make that for me at a reasanoble price. Thanks in advance for your postins. Pataclaun

  • Resume downloading and other bug

    Hi  ! everybody ! and sorry  for my bad english. i have a persistant problem with logic x the first time i had this problem was when i started to used logic x on my imac i7, in july,  it repeat t me often to download some sample file or  sound bank f

  • Backing Up a CD. How please?

    I need to copy a CD but am not sure how to go about it on the Mac, the last CD I copied I did with Nero on a PC, but as I no longer own a PC I'm a bit stuck. Help please. On another subject, my email spell checker is in US English how do I change it

  • Issue in ME27

    Hi Gurus, I have created two new plants for a new company code. I have done all the customizations for STO. (Intra). Created a vendor and assgned it to supplying plant. Created a customer and assigned it to the receiving plant in customization. Suppl