JAXB marshalling complexType elements

Does anyone know why JAXB always marshalls complexType elements with a seperate start and end tag, even if the element has no content?
i.e.
Given the schema element declaration:
<xs:element name="foo" type="fooType"/>
<xs:complexType name="fooType">
<xs:attribute name="value" type="xs:string" use="required"/>
</xs:complexType>
Why do I get:
<foo value="bar"></foo>
Instead of:
<foo value="bar"/>
Is their a setting / property to control this behaviour?
If not then I certainly think there should be because this will bloat the 5Mb XML files I am currently dealing with by quite a lot.
Cheers,
Simon

I have exactly the same trouble here. Did you find a solution? If so, please contact me. I am so afraid of increase the amount space used to store all XML files.
Thanks in advance
Julio Garc�a
[email protected]

Similar Messages

  • JAXB Marshalling of "double" problem - exponent is in the way

    An element declared as "xsd:double" in the schema is marshalled by JAXB as "3.000404E-4" to represent 0.0003000404 . When I try to process this XML document using XSLT, the standard number() function returns "NaN" because of the exponent in the representation of the number.
    Is there any way to have JAXB marshall this number in a way that is acceptable to XSLT?
    Thanks,
    -Allan

    This seems to have a solution by using JAXB custom bindings. See http://forum.java.sun.com/thread.jsp?forum=34&thread=507037
    Thanks anyway.
    -Allan

  • JAXB marshal "lt;" and "gt;" instead " " and " "... URGENT

    Hi!
    I defined in jaxb that some tag (un)marshal (from/to) org.w3c.dom.Document.
    But when jaxb marshalling, the assigned document has got
    "lt" instead "<"
    "gt" instead ">".
    This is "equals" characthers when is represent in browser, but itegrity of xml file in not same.
    How can I forced "<" and ">"?
    Please, can me anybody help?

    I assume you mean it displays the following substitutions in the output document.
    & lt;      <      less than
    & gt;      >      greater than
    & amp;      &      ampersand
    & apos;      '      apostrophe
    & quot;      "      quotation mark
    { I have had to add an artificial space after the & in the entity reference, to prevent this forum from doing the entity reference subsititution even!}
    These are predefined entity references, which are required for valid xml. Since xml element are delimited by '<' and '>', the parser needs to know that you are not trying to define new elements when you use these characters in element text.
    If you use a parser on the output xml, you will get '<' and '>' back as the resulting element text.
    Scott
    http://www.swiftradius.com

  • JAXB Marshalling

    Hi,
    jaxb marshalling for a xml file takes 8 secs in one system but it takes 1/2 min in another system for the same file. I want to know how to identifyu if there is any difference in the parsers being useed. I searched the Manifest files but unable to find reference to the parser being used. I even compared the version numbers of the API in the Manifest file and all the jars seem to be same version.
    Please help me in identifying what could be the problem.
    Thanks,
    Ravinder

    I don't know anything about either of the computers involved or the XML document involved, but I will take a guess and say there are differences in network access between the two computers.

  • JAXB Marshalling devouring memory

    Hi there.
    I noticed some disturbing behavior with how JAXB marshals large XML documents. I have around 5000 data objects which, when marshalled, result in an XML document about 9.5 mb in size. Prior to calling marshal(), I had over 47mb available on my Heap. Before this method returned, an OutOfMemoryError had been thrown. I was able to fix this problem by setting my max Heap size to 128mb.
    My concern is how this will scale with larger data sets, as I don't want to keep throwing more and more ram at the problem. I haven't run any concrete benchmarks yet, but I was wondering if anyone has run into this problem before and could share some numbers with me.
    Thanks in advance!

    Immediately prior to calling marshal(), I have approx 47 mb available out of an original 64. So for 5000 catalog items, I'm using a max of 17 mb; that's 3.4 k for each item bound to JAXB. That's not unacceptable. The problem is that in the process of marshalling this data to XML, over 50 mb is being consumed. This XML is sent to a remote Web Service (the spec allows for xml up to 35mb), so the size of the document is not unreasonable.
    I did a little benchmarking, and found this behavior to scale fairly linearly, which is a Good Thing (128mb per 9000 items). However, I'm wondering if JAXB allows for more efficient memory management for marshalling larger data sets (i.e. Serializing binding objects to disk until it's time to build them to xml, or releasing objects as soon as they're marshalled).

  • JAXB marshaling and unmarshaling

    I used JAXB to generate nine classes (one is simply a type-safe enum) to correspond to my XML DTD. I then wrote the code to instantiate the root and some child elements which are all added to the root content. Then I am able to call validate() and marshal() on the root element and produce the desired XML. Great!
    The trouble is that I'm having difficulty using these classes to unmarshal the XML that they validated and wrote. Has anyone else seen this? In some cases, the call to unmarshal() returns the root element with no content (e.g., "<myRoot/>"). In other cases, I get an InvalidContentException on a nested element that repeats (e.g., "Expected an end tag for a "fooList" element, but found a start tag for a "foo" element").
    Has anyone else seen this? I've been through the bug parade and didn't catch this mentioned there.
    Thanks!
    Mark

    Here's the code for the problem I'm running into. Is anyone able to reproduce the problem and diagnose it? I must be doing something wrong because the Checkbook example works just fine for me. Please help!
    The obvious trouble here is that Test4.java does not correctly unmarshal the XML that it writes to temp.xml. Where have I gone wrong?
    Thanks,
    Mark
    -------- begin cut (xyz.dtd) --------
    <!ELEMENT Id ( #PCDATA ) >
    <!ELEMENT Name ( #PCDATA ) >
    <!ELEMENT Amt ( #PCDATA ) >
    <!ELEMENT Transaction ( Id, Name, Amt ) >
    <!ELEMENT Transactions ( Transaction+ ) >
    <!ATTLIST Transactions count NMTOKEN #IMPLIED >
    --------- end cut (xyz.dtd) ---------
    -------- begin cut (xyz.xjs) --------
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <xml-java-binding-schema version="1.0-ea">
    <options package="xyz"/>
    <element name="Transactions" type="class" root="true">
    <attribute name="count" convert="int"/>
    <content>
    <element-ref name="Transaction"/>
    </content>
    </element>
    <element name="Name" type="value"/>
    <element name="Amt" type="value" convert="int"/>
    <element name="Id" type="value" convert="int"/>
    <element name="Transaction" type="class">
    <content>
    <element-ref name="Id"/>
    <element-ref name="Name"/>
    <element-ref name="Amt"/>
    </content>
    </element>
    </xml-java-binding-schema>
    --------- end cut (xyz.xjs) ---------
    -------- begin cut (Test4.java) --------
    import xyz.*;
    import javax.xml.bind.*;
    import javax.xml.marshal.*;
    import java.io.*;
    import java.util.Date;
    import java.util.Random;
    public class Test4 {
    private static Random rand = new Random();
    public static void main(String[] args) {
    // need file to work with...
    try {
    File f = new File( "temp.xml" );
    FileOutputStream fout =
    new FileOutputStream( f );
    // make some transactions
    int TransCt = 1;
    Transactions txns = new Transactions();
    java.util.List transactions = txns.getTransaction();
    for (int i=0; i < TransCt; i++) {
    Transaction t = makeBogus();
    transactions.add( t );
    txns.setCount( TransCt );
    txns.validate();
    txns.marshal( fout );
    fout.flush();
    fout.close();
    FileInputStream fin = new FileInputStream( f );
    Transactions t = new Transactions();
    t.unmarshal( fin );
    t.validate();
    t.marshal( System.out );
    catch (Exception e) {
    e.printStackTrace();
    private static Transaction makeBogus() {
    String[] names =
    { "Bob", "Larry", "Tom", "Ted", "Bill",
    "Gail", "Louise", "Sam", "Erin", "Wilma" };
    Transaction transaction = new Transaction();
    // calculate transaction id...
    int range = Integer.MAX_VALUE / 3 * 2;
    int Id = rand.nextInt(range);
    transaction.setId( Id );
    // pick a name
    transaction.setName( names[rand.nextInt(10)] );
    transaction.setAmt( rand.nextInt( 100 ) );
    return transaction;
    --------- end cut (Test4.java) ---------

  • JaxB Javadoc on elements of classes generated

    I am using JaxB 1.0 and having problems getting Javadoc into the generated classes. I can get the javadoc from the xsd file into the generate class at the class level but not have the get setter level
    Below is a listing of what I have been able to get to compile but it does nothing to generate in the class on the following methods.
    void setInEjbContext(boolean value);
    com.acxiom.arch.configuration.schemaobjects.base.ContainerDatasources getContainerDataSources();
    <xsd:element name="UseActivationKeySecurity" type="xsd:boolean" default="true">
    <xsd:annotation>
    <xsd:appinfo>
    <jaxb:property>
    <jaxb:javadoc>
    When set to true KBA will use SECURITY_ROLE in the activation key params table associated with the service and check security.
    </jaxb:javadoc>
    </jaxb:property>
    </xsd:appinfo>
    </xsd:annotation>
    </xsd:element>

    That did not help. I can't get JaxB to put the java doc comments on elements in the generate classes. I can get package level and class level comments but not element level.

  • JAXB Marshalling without UnMarshalling

    Hi,
    Using JAXB can I Marshall an java object to xml directly without Unmarshalling it first?
    Thanks.

    well... yes, as long as the java object is in java binding format...

  • JAXB Marshalling Question

    below is what I get for marshalling some JAXB generated class instance, and i notice that several namespace was create ns1, ns2, ns3.... which are actually all sharing the same namespace, is there anyway (any option) that I can set to optimize it, so they can all simply use ns1, and won't define ns2, ns3...
    thank you.
    Jacob
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <aaa xmlns="http://schema.abc.com/def/gh">
    <ns1:HeaderReq xmlns:ns1="http://schema.abc.com/def">
    <ns1:Header>
    <ns1:sessionToken>sessionToken</ns1:sessionToken>
    <ns1:language>eng</ns1:language>
    <ns1:version>version2</ns1:version>
    </ns1:Header>
    <ns1:ddd>web</ns1:ddd>
    <ns1:eee>a</ns1:eee>
    </ns1:HeaderReq>
    <ns2:ccc xmlns:ns2="http://schema.abc.com/def">accountToken</ns2:ccc>
    <bbb>
    <ns3:firstName xmlns:ns3="http://schema.abc.com/def">Jacob</ns3:firstName>
    <ns4:lastName xmlns:ns4="http://schema.abc.com/def">Tseng</ns4:lastName>
    <relationship>SON</relationship>
    </bbb>
    </aaa>

    Hi Jacob,
    Here is the solution I used for getting rid of ns1,ns2 etc..when I was getting ns1,ns2.. etc.along with http://www.xyz.com/xml/yourxml in the generated XML output
    It worked for me. Let me know if you need any further help.
    -bhanu
    Please include the Following Code when you are marshalling the Document
    ======================== Your Main Java File ======================
    try {
              m.setProperty("com.sun.xml.bind.namespacePrefixMapper",new NamespacePrefixMapperImpl());
    // m is the Marshaller Object
    // NamespacePrefixMapperImpl()
    // You have to implement, sample code is given below
         catch ( PropertyException pe)
              System.out.println("Property Exception : " + pe.toString());
    ===============================================================
    Here is the Sample Code to implement NamespacePrefixMapperImpl()
    =========================================================
    import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
    class NamespacePrefixMapperImpl extends NamespacePrefixMapper {
    public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
    // W3c to show a prefix "xsi"
    if( "http://www.w3.org/2001/XMLSchema-instance".equals(namespaceUri) )
    return "xsi";
    // Your namespace http://www.xyz.com/yourxml/ to show prefix "tns"
    if( "http://www.xyz.com/yourxml/".equals(namespaceUri) )
    return "tns";
    return suggestion;

  • Jaxb and container elements

    Hi,
    Consider this XML:
    <container>
    <items>
    <item/>
    <item/>
    <item/>
    <!-- ... -->
    </items>
    </container>
    as of now, to get a list of items I need to make two calls: the first to get the object corresponding to the <items> element, and the second to get the actual items (e.g. container.getItems().getItems()).
    Is it possible to create a complex type or a binding that would let me get item list in a single call (e.g. container.getItems())?

    If test.xsd looks like this:
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="container">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="items">
    <xs:complexType>
    <xs:sequence minOccurs="1" maxOccurs="unbounded">
    <xs:element name="item"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    and you compile it like this:
    xjc -p test test.xsd
    this will create bindings that should let you unmarshal your instance into a Container class. That class will contain a getItem() method that returns a java.util.List of items.
    -- Ed

  • JAXB - Marshalling populated Java object into XML

    I have a populated Java object that I'd like to marshall to an xml file.
    I don't instantiate this object from a DTD, nor do I need to generate the object via unmarshalling an xml. I'm just trying to build something akin to a toXML() method for this object.
    Is JAXB what I should be using?
    Any suggestions?
    Thanks a lot.
    Paul

    Hi Paul,
    Did you ever sort this out?
    I too am now having problems with Marshalling to and from XML.
    I have been able to write my own Marshalling class but can't seem to be able to DeMarshal a XML stream to a SOAP object.
    Please reply to this message if you are able to maybe shed some light on my problem.
    I have a populated Java object that I'd like to
    marshall to an xml file.
    I don't instantiate this object from a DTD, nor do I
    need to generate the object via unmarshalling an xml.
    I'm just trying to build something akin to a toXML()
    method for this object.
    Is JAXB what I should be using?
    Any suggestions?
    Thanks a lot.
    Paul

  • JAXB-marshalling problem

    I am trying to use JAXB for binding. The schema compiler works ok i.e i have got the classes generated but when now when i try to apply marshalling i get an error
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/MarshallableObject
    could anyone help what could be the problem with this.
    Any help is appreciated.
    satya

    i am also getting the same error
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/MarshallableRootElement
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at NodeLister.main(NodeLister.java:46)
    i do not know what to do now...i am stuck

  • ComplexType Elements using Axis

    I am creating a dynamic web service client using Axis that can call any operation, given only the WSDL file. Everything was going fine until I had to return a complexType. I am able to retrieve the complexType, however I am unable to get the 'name' of each element.
    Here is a snippet of the WSDL:
    <complexType name="MyDataType">
    <sequence>
    <element name="aNumber1" nillable="true" type="xsd:string"/>
    <element name="aNumber2" nillable="true" type="xsd:string"/>
    <element name="aNumber3" nillable="true" type="xsd:string"/>
    </sequence>
    </complexType>When I print out the invocation of the Call, I get something like the following:
    [15, 10, 100]
    Is there any way to retrieve the element name (ex: aNumber1, aNumber2, etc) from the returned object? For this operation, I registered the ArraySerializer/DeserializerFactory but I couldn't find anything to allow me to access the element names.
    Thanks.

    I am creating a dynamic web service client using Axis that can call any operation, given only the WSDL file. Everything was going fine until I had to return a complexType. I am able to retrieve the complexType, however I am unable to get the 'name' of each element.
    Here is a snippet of the WSDL:
    <complexType name="MyDataType">
    <sequence>
    <element name="aNumber1" nillable="true" type="xsd:string"/>
    <element name="aNumber2" nillable="true" type="xsd:string"/>
    <element name="aNumber3" nillable="true" type="xsd:string"/>
    </sequence>
    </complexType>When I print out the invocation of the Call, I get something like the following:
    [15, 10, 100]
    Is there any way to retrieve the element name (ex: aNumber1, aNumber2, etc) from the returned object? For this operation, I registered the ArraySerializer/DeserializerFactory but I couldn't find anything to allow me to access the element names.
    Thanks.

  • Jaxb -binding specific elements of schema to class

    Is there a way to bind only specific elements from a schema to a class instead of binding everything in the schema. If yes, how do you specify this.

    The <class> binding declaration customizes the binding of a schema element.
    http://java.sun.com/xml/jaxb/users-guide/jaxb-custom.html#customdesc_class

  • JAXB namespace common elements

    Hi,
    I'm generating a parser according to 3 DTDs:
    main.dtd
    devinf.dtd
    metinf.dtd
    I have translated the DTDs in 3 XML schemas with DTD to XML Schema translator (found on w3c) that Translate a Document Type Definition (XML 1.0 DTD) into an XML schema (REC-xmlschema-1-20010502):
    http://puvogel.informatik.med.uni-giessen.de/dtd2xs/
    The main.dtd contains an element Meta defined such as:
    <!-- Meta element type -->
    <!-- Element types in the content MUST have name space declared. -->
    <!--The Meta content would be something such as:
    <Meta>
    <Type xmlns='metinf'>myType</Type>
    <Format xmlns='metinf'>myFormat</Format>
    </Meta>-->
    <!ELEMENT Meta (#PCDATA)>
    AND 2 elements Format and Type!!!!
    Converting to Schema:
    <xs:element name="Meta" type="xs:string" />
    <xs:element name="Format" type="xs:string" />
    <xs:element name="Type" type="xs:string" />
    The metinf DTD defines the elements Type and Format such as after converting in schema we have:
    <xs:element name="Format" type="xs:string" />
    <xs:element name="Type" type="xs:string" />
    The devinf DTD defines also these two elements !!!!
    I tried to modify the main schema to import the devinf and metinf schema. However when I try to compile, I receive the error that the compiler atempts to generates the same interface (Format and Type) from the 3 different schema.
    (compile line is:
    xjc -jar %JAVA_LIBS%\jaxb-xjc.jar -p mypackage devinf.xsl metinf.xsl main.xsl)
    How could I do to obtain a Parser that could read and write the following XML:
    <!-- These Format and Type refer to main.dtd -->
    <Format>formatA</Format>
    <Type>typeA</Type>
    <Meta>
    <!-- These Format and Type refer to metinf.dtd -->
    <Format xmlns="metinf">formatB</Format>
    <Type xmlns="metinf">typeB</Type>
    </Meta>
    <!-- These Format and Type refer to devinf.dtd -->
    <Format xmlns="devinf">formatC</Format>
    <Type xmlns="metinf">typeC</Type>
    Many thanks and sorry for my poor english!

    Sorry to disturb you....
    Sometimes you found you are really stupid.
    The solution for the above problem is to define a custom binding (specifying per example a different package for the different DTDs)
    Sorry again
    Tanguy

Maybe you are looking for

  • Report for loans given to customer

    hi to all,            i m new to abap, i have requirement for developing a report that list loans given to customer.im unable to find table for loans please help me out .its very very urgent.

  • Flashing Black Screen

    Several days ago, Windows XP updated, and my iPod was plugged in to charge. The update did not work as expected and my computer didn't work for several days. Afterward, I unplugged my iPod properly, disconnecting it first from iTunes and secondly fro

  • How to run a project which gets parameters from a batch file

    Hello all, I use to run a program, which gets parameters only by interactive mode, using a batch file as you can see below: # myprogram < batchfile.txt Now, I'm updating its code by SunStudioExpress IDE and I'd like to run it from the batchfile. I ha

  • Cannot locate Address Bar, Rss button or Google

    Cannot locate Address Bar, Rss Button or Google. Under File, Find location is not available.

  • Import stops with 'Transport set created, exported, and submitted...'

    Hi, I'm using Oracle Portal 10.1.4, and I've successfully imported page groups into this portal before, but now when I try to do an import, I only see the following message in the 'Browse Transport Sets' page: Import: Transport set created, exported,