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;

Similar Messages

  • 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 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 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 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

  • MSI Big Bang Marshal - Questions

    Hello all
    I am new here and I have been doing research on components for a new computer I am making a shopping list for. I have a few questions I have not been able to find any information online. Here goes
    1. Anything specific I should know about the motherboard other then whats in the specs? Problems, quirks, etc?
    2. Does the motherboard only support 2x Dual Video cards like 2x Nvidia GTX 590 or can I use 4x Nvidia GTX 480s?
    3. P67 motherboards with the nf200 on them support 24 pci-e lanes. if I use:
    PCI_E1 - 8x
    PCI_E3 - 8x
    PCI_E5 - 8x
    PCI_E7 - 8x
    Makes up 24
    But there are still:
    PCI_E2 - 1x
    PCI_E4 - 1x
    PCI_E6 - 1x
    PCI_E8 - 1x
    Left. Does that mean there are no lanes left and I coudnt even fill anything in the other 4 slots like PCI-E Sound, etc?
    4. If you do Dual, Tri, Quad-SLI and have a PhysX card, how many PCI-E lanes will your PhysX card consume? Is it set by the NVIDIA control panel, the number of lanes of the chipset divided by the mount of video cards or by the card itself?
    5. When people say Dual, Tri, Quad-SLI +PhysX, does it mean (Dual -1(PhysX), Tri -1(PhysX), Quad -1(PhysX) or does it mean (Dual +1, Tri +1, Quad +1)?
    6. I know Scalability of increasing arrays of video cards is pretty poor, but could I do Quad SLI +PhysX using the MSI Big Bang Marshal?
    7. Which is most advantageous, Tri SLI +PhysX, Quad SLI, Quad SLI +PhysX?
    8. Sorry, probably not related, but I wanted to do Raid with SSD's for very fast reads and writes yet have redundancy. I wanted to get some OCZ Vertex 3s and I was reading about how Raid 5 was interesting but apparently Raid 5 increases the degredation of SSD? Has anyone experienced this or have any suggestions on best raid configurations?
    Thank you for all of your help

    Quote
    P67 motherboards with the nf200 on them support 24 pci-e lanes. if I use:
    PCI_E1 - 8x
    PCI_E3 - 8x
    PCI_E5 - 8x
    PCI_E7 - 8x
    Makes up 24
    By my count, that makes 32 lanes. If not done so, a lot of pre preparation information can be gathered at the MSI Global Website. All the basic & more detailed information can be found there. The downloadable pdf manual is usually much more comprehensive than the manual that comes with the board as well, & can probably answer a lot of your questions. I don't believe the board can do Quad GTX 480 SLI.

  • 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 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 Related Question

    Hi All,
    I have started working on JAXB 1.4 reference implementation provided by sun. I have following questions.
    1. Do we have any implementation which simply has the Jar files which can be placed in the classpath and can be used. Right now this reference implementation from sun has lot other things also.
    2. I have bee able to use JAXB 1.4 with JDK1.3.1_08 ad as far as what I am tryig to do it looks fine. Are there any issue's with JDK 1.3.1 because I have see somewhere in the documentation it recommends JDK 1.4.
    Thanks,
    Alok

    If you're planning to redistribute JAXB, the license requires you to include a subset of the libraries:
    https://jaxb.dev.java.net/faq/index.html#runtime_jars
    http://java.sun.com/webservices/docs/1.4/ReleaseNotes.html#RedistributableComponents
    Otherwise, just make sure the libraries in that list are in your CLASSPATH. $JWSDP_HOME/jaxb/bin/xjc.bat does that for you. Or, you can run jaxb-xjc.jar:
    http://java.sun.com/webservices/docs/1.4/jaxb/xjc.html
    You should be fine on 1.3.1_b08, but we did all our JDK 1.3 testing on 1.3.1_10-b03.
    -- Ed

  • JAXB Unmarshalling question

    I want to create Java objects from an XML file; JAXB sounds like the way to go, from what I've read.
    One question though: the object I want to create is an existing class. What I'd like to do is have JAXB create objects of the existing class, instead of the bean class that the JAXB binding compiler creates from looking at the schema.
    Is there a way to do this? Am I using the wrong tool? The existing class does not adhere to the bean standard.
    Thanks!

    Hi,
    You could place the binding schema,xml document,dtd could be at any location on your filesystem.When you use the binding compiler, you need to specify the location.
    For ex. you could use as following:
    D:\Softwares\jwsdp1.2\jaxb\bin\xjc -b c:\binding.xjb d:\examples\example.xsd
    If your are using jwsdp1.3, you need to set the JAVA_HOME and JWSDP_HOME environment variables.
    Refer the section "configuring and running the samples" for details at http://java.sun.com/webservices/docs/1.3/tutorial/doc/JAXBUsing2.html#wp87739
    -Amol

  • JAXB class question

    does anyone know which jar file has the javax.xml.XMLConstants class? I'm getting an error while going through some examples for JAXB and I am almost positive that my classpath is messed up or not pointing to the right jars.

    Good job mate. That's the way!
    And you came back and let us know we needn't waste precious time answering a solved question. That's just exellent. Thanks.
    :)

  • 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

  • JAXB marshal and unmarshal

    hello,
    i have written some code to retrieve data from an XML file and mapped the data and display the mapped data in a new XML file, but i am able to display the mapped data in an MSdos window by running ANT, after this i am unable to write the displayed data in to XML file.
    Input XML file holds --- Firstname(Hello) and
    Lastname(World)
    my MSdos display data ----------- Hello World
    is in this way
    I want the above out put in to XML file
    if any body know this help me.
    Thank you.

    IMHO these classes are not meant to be serialised, the XML produced is the medium that is tranmitted between programs. The XMLB classes are available at both ends to do the marshalling/unmarshalling.I dissagree, xml is just an interface to the outside world, so to speak. I'm working with a project that uses jini and rmi, I really don't need the extra hasle of writting custom serialization classes.

  • JAXB - Newbie Question

    Hi,
    I am new to JAXB. I installed the JAXB1.3 in unix. I am having a little bit of trouble figuring out a few things
    1. where should the DTD be placed relative to the installation directory
    2. Where should the XML document be placed
    3. Where should the binding schema be placed
    4. What environment variables should be included in the CLASSPATH.
    Would appreciate any assistance,
    Thanks,
    Safeena

    Hi,
    You could place the binding schema,xml document,dtd could be at any location on your filesystem.When you use the binding compiler, you need to specify the location.
    For ex. you could use as following:
    D:\Softwares\jwsdp1.2\jaxb\bin\xjc -b c:\binding.xjb d:\examples\example.xsd
    If your are using jwsdp1.3, you need to set the JAVA_HOME and JWSDP_HOME environment variables.
    Refer the section "configuring and running the samples" for details at http://java.sun.com/webservices/docs/1.3/tutorial/doc/JAXBUsing2.html#wp87739
    -Amol

Maybe you are looking for

  • Error while assigning portal custom role

    Hi All, We have a custom role which we use to assign to the users.  till now we are able to assign it without any problem.  But now as i need to assign it to someone, i got an error stating that "An error occured while adding user assignments; to see

  • Uploading pages from a server to DW CS5 desktop

    My web pages need some changes in some areas of content and font family, color, point. If there is anyway to make the changes by viewing the pages in DW CS5. All images, font, css, frames, and tags, substituting the Web browser view for the DW CS5 de

  • Mm_menu.js not working in IE

    I know the old  mm_menu.js script and approch is old. But my client wants to get it the drop drown menu to work in IE. I have IE 9 but I don't think it works in 8 either.  I have read some older posts to use this hack by adding  an IE Emulate HTTP he

  • XercesImpl.jar & xerces.jar

    Hi, I am just wondering what version of xerces is present in xercesImpl.jar that comes with xmlbeans-1.0.4-jdk.1.3.jar Thank you AshB

  • Problems Playing Burned Disks

    So I've been at this all morning and I'm so frustrated. I've burned this one file onto a CD-R disk and it says that it's there however it won't play on my TV or when I pop the disk out and then pop it back into Mac it doesn't play there either. I've