XML Marshalling/Unmarshalling

All,
I am familiar with XMLBeans and JAXB. However, I would prefer not to use either of these for two reasons:
I am not a schema guru (not do I want to be)
I hate code generation in the build processI'm looking for something that would map an X-Path to a Java object. However, I do not want the tool to actually generate that Java object. Rather, a developer will.
Any technology out there that anyone has used that fits those requirements?
Thanks,
- Saish

BTW, sorry for posting so late, but I am heading out for the day. See you all in 16 hours. :^)
- Saish

Similar Messages

  • XML marshalling / unmarshalling javabeans and xsd rational

    Hoping someone can give ma starting point as I am having trouble
    finding any clear documentation. In Rational Application Developer you have the option to generate javabeans from an XML Schema document. My questions are:
    1) once you have generated your beans how can you use these files to
    marhall and unmarshall XML documents?
    2 )how does all of this compare to the JAXB api packaged in the
    webservices development pack?
    I am new to all of this and just looking for some good documentation,
    tutorials, and a starting point.
    Thanks!!!

    BTW, sorry for posting so late, but I am heading out for the day. See you all in 16 hours. :^)
    - Saish

  • Validate  XML against  XML Shema while marshalling/Unmarshalling in JAXB?.

    Hi,
    Can i validate XML documents against XML Shema when i marshall/unmarshall the same using JAXB API?.
    Thanks

    Well, it is weird, but, the code below works when validating the NonEmptyString type:
    XmlSchemaSet schemaSet = new XmlSchemaSet();
    schemaSet.Add(null, "LogConfig.xsd");
    XDocument doc1 = XDocument.Load("LogConfig.xml");
    doc1.Validate(schemaSet, new ValidationEventHandler(ValidationCallBack), false);
    However, if I leave the <LogName> empty it does not valid the values set on xsd fixed attribute, 
    The solution?
    Well, I'm validating the same xml twice, the code above and the code on my first question.

  • Character encoding conversion for marshall/unmarshall?

    Hello, Java Web Services gurus,
    I am wondering if there is an easy/plugin-able way to do character encoding conversion transparently in the process of marshall/unmarshall.
    Basically, my input/output will always be these UTF-8 XMLs. As the backend database is ISO encoded, I hope the result of unmarshall will give me ISO strings. And when it comes to marshall, the ISO strings can be transparently turned to UTF-8 XML response. Right now I'm using JAXB's annotations to parse XML into objects.
    I understand there will be chars in the input file not able to get converted, if so, I'd be be expecting an error/exception that flags the failure
    Hope I sound clear. This has been a headache for a while. Really hope someone may help out a bit. Thanks a million in advance

    [Duplicate Post|http://forums.sun.com/thread.jspa?messageID=10971554&tstart=0#10971554]

  • Code:com.bea.xml.marshal.XmlEncodingException String:Unrecognized element

    I am connecting to an external web service. However, I am getting the XmlEncodingException.
    Failure=com.bea.control.ServiceControlException: SERVICE FAULT:
    Code:com.bea.xml.marshal.XmlEncodingException
    String:Unrecognized element ...
    Here is the stack trace.
    at com.bea.wlw.runtime.core.control.ServiceControlImpl.invoke(Ljava.lang
    .reflect.Method;[Ljava.lang.Object;)Ljava.lang.Object;(ServiceControlImpl.jcs:12
    37)
    at com.bea.wlw.runtime.core.dispatcher.DispMethod.invoke(Ljava.lang.Obje
    ct;[Ljava.lang.Object;)Ljava.lang.Object;(DispMethod.java:373)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Ljava.lang.Object
    ;Ljava.lang.String;Lcom.bea.wlw.runtime.core.dispatcher.DispMethod;[Ljava.lang.O
    bject;)Ljava.lang.Object;(Invocable.java:423)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Lcom.bea.wlw.runt
    ime.core.dispatcher.DispMethod;[Ljava.lang.Object;)Ljava.lang.Object;(Invocable.
    java:396)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Lcom.bea.wlw.runt
    ime.core.request.Request;)Lcom.bea.wlw.runtime.core.dispatcher.InvokeResult;(Inv
    ocable.java:248)
    at com.bea.wlw.runtime.jcs.container.JcsContainer.invoke(Lcom.bea.wlw.ru
    ntime.core.request.Request;)Lcom.bea.wlw.runtime.core.dispatcher.InvokeResult;(J
    csContainer.java:84)
    at com.bea.wlw.runtime.core.bean.BaseContainerBean.invokeBase(Lcom.bea.w
    lw.runtime.core.request.Request;)Lcom.bea.wlw.runtime.core.dispatcher.InvokeResu
    lt;(BaseContainerBean.java:198)
    at com.bea.wlw.runtime.core.bean.SLSBContainerBean.invoke(Lcom.bea.wlw.r
    untime.core.request.Request;)Lcom.bea.wlw.runtime.core.dispatcher.InvokeResult;(
    SLSBContainerBean.java:103)
    at ...
    at com.bea.wlwgen.StatelessContainer_ngdnix_ELOImpl.findTdaByZip(Lcom.be
    a.wlw.runtime.core.request.Request;)Lcom.bea.wlw.runtime.core.dispatcher.InvokeR
    esult;(StatelessContainer_ngdnix_ELOImpl.java:153)
    at
    at com.bea.wlw.runtime.core.bean.BaseDispatcherBean.runAsInvoke(Lcom.bea
    .wlw.runtime.core.request.Request;)Lcom.bea.wlw.runtime.core.request.Response;(B
    aseDispatcherBean.java:153)
    at com.bea.wlw.runtime.core.bean.BaseDispatcherBean.invoke(Lcom.bea.wlw.
    runtime.core.request.Request;)Lcom.bea.wlw.runtime.core.request.Response;(BaseDi
    spatcherBean.java:54)
    at com.bea.wlw.runtime.core.bean.SyncDispatcherBean.invoke(Lcom.bea.wlw.
    runtime.core.request.Request;)Lcom.bea.wlw.runtime.core.request.Response;(SyncDi
    spatcherBean.java:160)
    at com.bea.wlw.runtime.core.bean.SyncDispatcher_k1mrl8_EOImpl.invoke(Lco
    m.bea.wlw.runtime.core.request.Request;)Lcom.bea.wlw.runtime.core.request.Respon
    se;(SyncDispatcher_k1mrl8_EOImpl.java:100)
    at com.bea.wlw.runtime.core.dispatcher.Dispatcher.remoteDispatch(Lcom.be
    a.wlw.runtime.core.dispatcher.DispFile;Lcom.bea.wlw.runtime.core.request.Request
    ;)Lcom.bea.wlw.runtime.core.request.Response;(Dispatcher.java:161)
    at com.bea.wlw.runtime.core.dispatcher.ServiceHandleImpl.invoke(Lcom.bea
    .wlw.runtime.core.request.Request;)Ljava.lang.Object;(ServiceHandleImpl.java:436
    at com.bea.wlw.runtime.core.dispatcher.WlwProxyImpl._invoke(Lcom.bea.wlw
    .runtime.core.request.ExecRequest;)Ljava.lang.Object;(WlwProxyImpl.java:326)
    at com.bea.wlw.runtime.core.dispatcher.WlwProxyImpl.invoke(Ljava.lang.Ob
    ject;Ljava.lang.reflect.Method;[Ljava.lang.Object;)Ljava.lang.Object;(WlwProxyIm
    pl.java:315)
    Any suggestions or ideas?

    Hey any solution for this problem ..
    I am having it.
    I am testing the webservice from a simple client and the test is succesfull but when I am running through workshop is gives me
    ata(); Failure=com.bea.control.ServiceControlException: SERVICE FAULT:
    Code:com.bea.xml.marshal.XmlEncodingException
    String:Unrecognized element item - expected
    Please help me in this.

  • What is marshalling/unmarshalling?

    And how is it different form Serialization/Deserialization?

    And the additional comment I would add to that explanation would be that while serialization/deserialization is usually performed on whole objects, marshalling/unmarshalling is a finer grained mechanism for the serialization/deserialization of just a parameter list and a return value ...with the actual method implementations left unexposed and secure.

  • Jabx xsd to classes and xml marshalling issues due to two namespaces

    Hello everyone,
    I am stack using jaxb and I ask for some help.
    My final objective is being able of marshalling and unmarshalling xml-s that follows the structure of this xsd:
    http://www.ipdr.org/public/VoIP3.5-A.0.1.xsd
    I have already generated the classes with xjc:
         xjc.bat VoIP3.5-A.0.1.xsd
    This generates the following class tree:
    parsing a schema...
    compiling a schema...
    org\ipdr\namespaces\voip\IPDRVoIPType.java
    org\ipdr\namespaces\voip\ObjectFactory.java
    org\ipdr\namespaces\voip\package-info.java
    org\ipdr\namespaces\ipdr\IPDRDoc.java
    org\ipdr\namespaces\ipdr\IPDRDocEnd.java
    org\ipdr\namespaces\ipdr\IPDRType.java
    org\ipdr\namespaces\ipdr\ObjectFactory.java
    org\ipdr\namespaces\ipdr\package-info.java
    Note that if you are behind a proxy and it is not configured it may fail.
    This is fine for now. Next step, I have the following xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Assumptions:
    Call is being made from cell phone to IP
    Call is terminated (normally) by the called side
    Optional and Conditional fields are included based on the type of call made
    Fields that did not include specific values (in the ipdr spec) have been
    populated with information based on SS7 equivalents
    IMSI/ESN/PIN/HLRID values are fictitious -->
    <IPDRDoc xmlns="http://www.ipdr.org/namespaces/ipdr"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.ipdr.org/public/VoIP3.5-A.0.1.xsd"
    IPDRRecorderInfo ="apex.virtualsummit.com"
    version="3.5-A.0.1">
    <IPDR>
    <seqNum>123</seqNum>
    <IPDRCreationTime>2000-02-01T07:00:00Z</IPDRCreationTime>
    <subscriberId>Vendor Phone-1</subscriberId>
    <ipAddress>172.17.17.10</ipAddress>
    <hostName>cisco.gateway.234</hostName>
    <imsiIngress>247478674378574</imsiIngress>
    <esnIngress>33375629401</esnIngress>
    <serviceConsumerType>EU</serviceConsumerType>
    <pin>6294621</pin>
    <startAccessTime>2000-11-25T09:45:30Z</startAccessTime>
    <startTime>2000-11-25T09:45:45Z</startTime>
    <endTime>2000-11-25T10:00:30</endTime>
    <timeZoneOffset>-480</timeZoneOffset> <callDuration>885</callDuration>
    <type>V</type>
    <feature>H</feature>
    <incomingCodec>G711Alaw</incomingCodec>
    <disconnectReason>normalCallClearing</disconnectReason>
    <averageLatency>145</averageLatency>
    <ani>214-924-0258</ani>
    <originalDestinationId>408-830-3711</originalDestinationId> <ipAddressEgressDevice>199.171.210.211</ipAddressEgressDevice>
    <portNumber>17779</portNumber>
    <homeLocationIdIgress>FF01ABD6</homeLocationIdIgress>
    <callCompletionCode>200</callCompletionCode>
    <uniqueCallId>id45678</uniqueCallId>
    </IPDR>
    </IPDRDoc>
    And I have the following classes:
    public class main {
         * @param args
         public static void main(String[] args) {
              Manager mng = new Manager();          
              mng.marshall();
              System.out.println("Agur mundua!");
    And:
    public class Manager {
         public void marshall() {
              try {
                   JAXBContext voip = JAXBContext.newInstance(
                             "org.ipdr.namespaces.voip", this.getClass()
                                       .getClassLoader());
                   Unmarshaller u = voip.createUnmarshaller();
                   // IPDRVoIPType po = (IPDRVoIPType)uvoip.unmarshal( new
                   // FileInputStream("files/example.xml"));
                   // IPDRType po = (IPDRType)uvoip.unmarshal( new
                   // FileInputStream("files/example.xml"));
                   // this implementation is a part of the API and convenient for
                   // trouble-shooting,
                   // as it prints out errors to System.out
                   u
                             .setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
                   // IPDRVoIPType structure = (IPDRVoIPType)u.unmarshal( new
                   // FileInputStream(
                   // "D:\\S3Lab-Projects\\Future Internet\\enviroment\\files\\example.xml"
                   JAXBElement<IPDRVoIPType> st = (JAXBElement) u.unmarshal(
                             new StreamSource(new File("files/example.xml")),
                             IPDRVoIPType.class);
                   IPDRVoIPType vtype = st.getValue();
                   System.out.println("ok");
              } catch (JAXBException je) {
                   je.printStackTrace();
    It gives me an exception saying that there are unexpected elements.
    If I use:
    JAXBContext voip = JAXBContext.newInstance(
                             "org.ipdr.namespaces.ipdr", this.getClass()
                                       .getClassLoader());
    JAXBElement<IPDRDoc> st = (IPDRDoc) u.unmarshal(
                             new StreamSource(new File("files/example.xml")),
                             IPDRDoc.class);
                   IPDRDoc vtype = st.getValue();
    I am able to read the attributes of IPDRDoc but not the ones from VoIP.
    My analysis is:
         The xml file is a IPDRDoc with VoIP3.5-A.0.1 elements
         JAXB does not know how to deal with xml that are spitted in various classes
         I cannot change any xsd files because they are standars
    So...
         What can I do to be able to marshall and unmarshall IPDRDoc xml with VoIP attributes generating the java classes from the standard xsd?
    Thank you for your time

    Hello everyone,
    I am stack using jaxb and I ask for some help.
    My final objective is being able of marshalling and unmarshalling xml-s that follows the structure of this xsd:
    http://www.ipdr.org/public/VoIP3.5-A.0.1.xsd
    I have already generated the classes with xjc:
         xjc.bat VoIP3.5-A.0.1.xsd
    This generates the following class tree:
    parsing a schema...
    compiling a schema...
    org\ipdr\namespaces\voip\IPDRVoIPType.java
    org\ipdr\namespaces\voip\ObjectFactory.java
    org\ipdr\namespaces\voip\package-info.java
    org\ipdr\namespaces\ipdr\IPDRDoc.java
    org\ipdr\namespaces\ipdr\IPDRDocEnd.java
    org\ipdr\namespaces\ipdr\IPDRType.java
    org\ipdr\namespaces\ipdr\ObjectFactory.java
    org\ipdr\namespaces\ipdr\package-info.java
    Note that if you are behind a proxy and it is not configured it may fail.
    This is fine for now. Next step, I have the following xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Assumptions:
    Call is being made from cell phone to IP
    Call is terminated (normally) by the called side
    Optional and Conditional fields are included based on the type of call made
    Fields that did not include specific values (in the ipdr spec) have been
    populated with information based on SS7 equivalents
    IMSI/ESN/PIN/HLRID values are fictitious -->
    <IPDRDoc xmlns="http://www.ipdr.org/namespaces/ipdr"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.ipdr.org/public/VoIP3.5-A.0.1.xsd"
    IPDRRecorderInfo ="apex.virtualsummit.com"
    version="3.5-A.0.1">
    <IPDR>
    <seqNum>123</seqNum>
    <IPDRCreationTime>2000-02-01T07:00:00Z</IPDRCreationTime>
    <subscriberId>Vendor Phone-1</subscriberId>
    <ipAddress>172.17.17.10</ipAddress>
    <hostName>cisco.gateway.234</hostName>
    <imsiIngress>247478674378574</imsiIngress>
    <esnIngress>33375629401</esnIngress>
    <serviceConsumerType>EU</serviceConsumerType>
    <pin>6294621</pin>
    <startAccessTime>2000-11-25T09:45:30Z</startAccessTime>
    <startTime>2000-11-25T09:45:45Z</startTime>
    <endTime>2000-11-25T10:00:30</endTime>
    <timeZoneOffset>-480</timeZoneOffset> <callDuration>885</callDuration>
    <type>V</type>
    <feature>H</feature>
    <incomingCodec>G711Alaw</incomingCodec>
    <disconnectReason>normalCallClearing</disconnectReason>
    <averageLatency>145</averageLatency>
    <ani>214-924-0258</ani>
    <originalDestinationId>408-830-3711</originalDestinationId> <ipAddressEgressDevice>199.171.210.211</ipAddressEgressDevice>
    <portNumber>17779</portNumber>
    <homeLocationIdIgress>FF01ABD6</homeLocationIdIgress>
    <callCompletionCode>200</callCompletionCode>
    <uniqueCallId>id45678</uniqueCallId>
    </IPDR>
    </IPDRDoc>
    And I have the following classes:
    public class main {
         * @param args
         public static void main(String[] args) {
              Manager mng = new Manager();          
              mng.marshall();
              System.out.println("Agur mundua!");
    And:
    public class Manager {
         public void marshall() {
              try {
                   JAXBContext voip = JAXBContext.newInstance(
                             "org.ipdr.namespaces.voip", this.getClass()
                                       .getClassLoader());
                   Unmarshaller u = voip.createUnmarshaller();
                   // IPDRVoIPType po = (IPDRVoIPType)uvoip.unmarshal( new
                   // FileInputStream("files/example.xml"));
                   // IPDRType po = (IPDRType)uvoip.unmarshal( new
                   // FileInputStream("files/example.xml"));
                   // this implementation is a part of the API and convenient for
                   // trouble-shooting,
                   // as it prints out errors to System.out
                   u
                             .setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
                   // IPDRVoIPType structure = (IPDRVoIPType)u.unmarshal( new
                   // FileInputStream(
                   // "D:\\S3Lab-Projects\\Future Internet\\enviroment\\files\\example.xml"
                   JAXBElement<IPDRVoIPType> st = (JAXBElement) u.unmarshal(
                             new StreamSource(new File("files/example.xml")),
                             IPDRVoIPType.class);
                   IPDRVoIPType vtype = st.getValue();
                   System.out.println("ok");
              } catch (JAXBException je) {
                   je.printStackTrace();
    It gives me an exception saying that there are unexpected elements.
    If I use:
    JAXBContext voip = JAXBContext.newInstance(
                             "org.ipdr.namespaces.ipdr", this.getClass()
                                       .getClassLoader());
    JAXBElement<IPDRDoc> st = (IPDRDoc) u.unmarshal(
                             new StreamSource(new File("files/example.xml")),
                             IPDRDoc.class);
                   IPDRDoc vtype = st.getValue();
    I am able to read the attributes of IPDRDoc but not the ones from VoIP.
    My analysis is:
         The xml file is a IPDRDoc with VoIP3.5-A.0.1 elements
         JAXB does not know how to deal with xml that are spitted in various classes
         I cannot change any xsd files because they are standars
    So...
         What can I do to be able to marshall and unmarshall IPDRDoc xml with VoIP attributes generating the java classes from the standard xsd?
    Thank you for your time

  • XML marshalling exception

    Hello,
    I'm using Toplink JAXB to generate XML document from java classes in a JSF application (all in JDeveloper 10.1.3).
    Everything works fine in JDeveloper embedded OC4J, but when deploed to OAS 10.1.3, the application gives the following exception:
    Exception [TOPLINK-25007] (Oracle TopLink - 10g Release 3 (10.1.3.0.0) (Build 060118)): oracle.toplink.exceptions.XMLMarshalExceptionException Description: A descriptor for class com.allstate.mqq.re.xao.jaxb.map.MqqrequestImpl was not found in the project]
    Has anyone experienced the same problem?
    Please help
    Thanks
    Kate

    See:
    Re: Toplink JAXB Marshalling
    -Blaise

  • Unable to parse the given xml by unmarshalling it

    Hi,
    I have to fetch the data from xml to java object. I am using castor parsing. i have written mapping xml which is mapped against the xml from which data is to be fetched. The entire application is working fine.
    The problem is if i have data like
    <CampaignName>&<</CampaignName>
    then the unmarshalling is gettig failed and dispalying error message as
    "The entity name must immediately follow the '&' in the entity reference"
    Actually the xml is valid against validation and is allowing to use &< combination as data. But it is requirement to use the same data.
    Please help me to resolve this problem.
    srinivas.

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.StringReader;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.CharacterData;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.InputSource;
    public class XMLParsingProj {
    public static void main(String arg[]) throws Exception {
    String xmlData = "";
    FileReader fileReader = new FileReader(new File("XMLData.xml"));
    BufferedReader bufReader = new BufferedReader(fileReader);
    String xmlLine = "";
    while ((xmlLine = bufReader.readLine()) != null) {
    xmlData += xmlLine;
    System.out.println("String Value is");
    System.out.println(xmlData);
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xmlData));
    Document doc = db.parse(is);
    NodeList nodes = doc.getElementsByTagName("soap:Envelope");
    for (int i = 0; i < nodes.getLength(); i++) {
    Element element = (Element) nodes.item(i);
    NodeList name = element.getElementsByTagName("soap:Body");
    Element line = (Element) name.item(0);
    System.out.println("Name: " + line.getTagName());
    NodeList title = element.getElementsByTagName("lookupResponse");
    line = (Element) title.item(0);
    System.out.println("Status: " + line.getAttribute("status"));
    System.out.println("data node length :" + nodes.getLength());
    }

  • Paramer marshalling/unmarshalling in jax-ws

    HI,
    Can we transit an complex-type parameter to some other types of java objects (like a Document object or something else) rather than java beans when we are using jax-ws?

    Yes, if you use Dispatch you can use a Source object. The JavaBean model
    is not required. Again the most flexible would be to use Dispatch.

  • XML parsing in CEP

    Hi All,
    I somehow strongly feel OCEP should have much more XML support.
    Firstly we need not to use XML marshalling/unmarshalling to and from Java classes.
    Secondly event definition could have supported through XSD(s).
    Lastly CQL should have a solid XML parsing capability (although it has some XQuery based naive support). If we had the support, it would have been much more easier send data directly from some bus (e.g. OSB) to OCEP and apply the pattern using CQL.
    Life would be much more simpler.... Isn't it?
    Regards
    Arijit
    Edited by: calvinIsMe on Oct 15, 2012 11:45 PM

    Hi Alex
    Nice to get feedback directly from creator.
    Always felt EDN integration is an obvious future step. I feel it kind of completes gaps in Oracle EDA offering. ESB (in this case SOA suite) can be biggest source of events in an enterprise.
    Having said that can we get some more details on what next release of OCEP is bringing along? Anything on CEP dashboard. Whenever we are trying to build a solution around CEP, we had to rely on BAM. No offense on BAM, that is indeed a powerful tool. But to represent a pattern of data graphically, it seems overkill. Or am I missing something?
    Regards
    Arijit
    Edited by: calvinIsMe on Oct 17, 2012 12:09 AM

  • Application objects factory?

    I've a xml config file that contains many nodes, each of them representing an object instance.
    When my simple java application start, i read the xml doc and want to instance an object for each node.
    I could do something like:
    List<MyItem> l = readXml("file.xml");
    readXml is something like a "factory" for my collection of objects.
    Is there a design pattern that I could emulate in order to do this?
    Thanks
    ago
    p.s. The task is pretty trivial so i'm not intrested in using persistence frameworks

    agostino75 wrote:
    Is there a design pattern that I could emulate in order to do this?I don't think a "design pattern" is what you're looking for, as you've already identified your factory. Simple XML marshalling/unmarshalling will work. You might also want to have a look at [Apache Commons Digester|http://commons.apache.org/digester/].
    ~

  • Inclusion of unused namespace declarations in marshalled XML

    Hello.
    I have noticed that by default any XML marshaled from an object contains namespace declarations related to every package specified when instantiating the JAXBContext even though they are not used in the instance being marshalled.
    Is there any way to avoid this during the marshalling as opposed to via some sort of post processing (e.g. XSLT transform).
    Example source below:
    package test;
    import javax.xml.bind.*;
    import java.io.*;
    import test.sample1.*;
    import test.sample2.*;
    public class Converter {
         public static void main(String[] args) {
              try {
                   String sample1 = "<Message1 xmlns=\"http://www.example.org/sample1\">" +
                                             "<tns:Field xmlns:tns=\"http://www.someother.org\">value</tns:Field>" +
                                        "</Message1>";
                   String sample2 = "<Message2 xmlns=\"http://www.example.org/sample2\">" +
                                            "<Field1>value1</Field1>" +
                                            "<Field2>value2</Field2>" +
                                        "</Message2>";
                   JAXBContext ctx = JAXBContext.newInstance("test.sample1:test.sample2");
                   Unmarshaller um = ctx.createUnmarshaller();
                   Marshaller m = ctx.createMarshaller();
                   StringWriter sw1 = new StringWriter();                
                   Message1 msg = (Message1)um.unmarshal(new StringReader(sample1));
                   m.marshal(msg, sw1);               
                   System.out.println("Marshalled sample1: \n"+sw1.toString());
                   StringWriter sw2 = new StringWriter();                
                   Message2 msg2 = (Message2)um.unmarshal(new StringReader(sample2));
                   m.marshal(msg2, sw2);               
                   System.out.println("Marshalled sample2: \n"+sw2.toString());
              } catch (JAXBException e) {
                   e.printStackTrace();
    }Produces output:-
    Marshalled sample1:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?><Message1 xmlns:ns2="http://www.example.org/sample2" xmlns="http://www.example.org/sample1"><tns:Field xmlns:tns="http://www.someother.org">value</tns:Field></Message1>
    Marshalled sample2:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:Message2 xmlns:ns2="http://www.example.org/sample2" xmlns="http://www.example.org/sample1"><ns2:Field1>value1</ns2:Field1><ns2:Field2>value2</ns2:Field2></ns2:Message2>

    Thanks for the quick response. I really appreciate it.
    Yes, as you say, there is no real problem as such but part of my app lets the user see the RAW message XMLs and this could confuse them and would be tidier to remove but I can also see why it is easier from the Marshaller perspective not to have to back track to remove unused declarations.
    Also, I'm a little concerned about the increased size of the XML produced. One of my webservices does handle quite a few different types and our Oracle namespace URLs are all pretty long!
    Like I say, I can see a way to get rid of them after the fact but wondered if there was a more elegant/performant way.

  • Using XML as persistance

    I'm re-writing a swing client that uses regular serialization to files in order to save user data. The data that needs to be persisted to file is very hierarchical by nature. I'm using MVC throughout the application.
    Now, I'm considering using XML as the file format for the persistence. I've written an XML schema (xsd) that dictates the data model.
    As I've stumbled upon XStream before I first had a look at that for marshalling/unmarshalling my XML. XStream is wonderful but it kind of makes the XML schema validation useless as I see it. So, now I'm looking at JAXB (or maybe XMLBeans) instead as the API between my XML files model layer in the application.
    Basically, what I'm looking for is a convenient way to read XML data from file into my data model. Obviously I want to be able to create XML from my data model as well. Will JAXB really save me from doing all the mapping between the XML and data model (POJO's) based on my XML schema?
    Am I barking at the wrong tree here? Also, please stop me if you think that XML are a ridiculous way of persisting application data.
    Thanks in advance!

    Thank you for your input DrClap!
    My Swing app is kind of a CAD app where users can make drawings of marinas. Objects can be moved, rotated, connected to each other and grouped and each object has a set of properties. The drawing layout, object props and calculation parameters needs to be persistent. Think MS Visio... Target audience is marine engineers that needs to make force calulations.
    Generating an xml file from my xml schema produces a file on about 7Kb (about 200 lines). A real life file would probably be at least 10 times bigger.
    I don't see an issue with updating or adding single elements in the XML. This is only done when the user saves to file, in all other cases the application would store data in the model layer. And as I understand it JAXB would handle all XML marhsalling/unmarshalling automagically.
    The only thing I'm worried about is having JAXB generating the model classes from my xml schema (xsd). Since I'm working with MVC my current model classes all fire property change events to its controllers whenever a setter is called. This would be lost if JAXB would generate the model for me. Am I right? My assumption with JAXB/XMLBeans is that you update the model by changing your xml schema and then generate/compile you model classes (and ObjectFactory).
    Thank you for taking your time to read this!

  • How to create an XML fril from an XML instance

    i have already created an instance of the xml using the classes generated from
    the SCHEMA, how will i generate an xml file from the instance i have? is it the
    same like the marshalling/unmarshalling Castor is doing? help please!!!

    It worked, Thanks so much!
    "Steve Traut" <[email protected]> wrote:
    Manuel -- If you simply want to write out the XML you've created, you
    can
    use one of the save methods exposed by your generated XMLBeans types.
    For
    example, to write the XML out to a file, you might do this:
    File myFile = new File("c:/myXml.xml");
    try
    myNewXmlDoc.save(myFile);
    catch (java.io.IOException ioe)
    System.out.println("Error while writing my XML file");
    Note that other save methods are available to write to other formats.
    Steve
    "Manuel Pantaleon" <[email protected]> wrote in message
    news:3f9f9312$[email protected]..
    i have already created an instance of the xml using the classes generatedfrom
    the SCHEMA, how will i generate an xml file from the instance i have?is
    it the
    same like the marshalling/unmarshalling Castor is doing? help please!!!

Maybe you are looking for

  • GL account automatically cleared by the bank statemetn document

    Hello all, I would like to ask you a question. We have done the payments by payment run to the vendor , FI document 2000008482  has been created, Then we received the bank statement which created the document 101481822 and the GL account used for thi

  • Order Status Report (by CO Business Transaction

    Hi All, At present, we are using standard IO Reports that give output of all the Orders (even closed ones). User wants a Report that gives output (or in other words they can select) by "status" of the order (e.g. they don't want to see whatever happe

  • New sequence vs new project

    Hey guys, quick question. I'm putting together something that is going to end up being 12 dvd's...all separate in their own right. Each dvd will share some of the same chapters...but will still be their own entity. I have all the clips that I'm using

  • Cancel and Keep Workitem ....Not Working

    Hi, We need your help in resolving a workflow issue. Issue is, When user gets an Invoice to approve (Non PO), she opens the invoice, do some changes, and park it. Then she gets Option button to either u201CApproveu201D, u201CRejectu201D, u201CCancel

  • How to use forfiles= without recreating over and over?

    I'm struggling trying to get some file testing done and can't figure what the right combination of commands should be. The goal is to have a number of files created (64, for example), then run different tests on those files, varying the number of fil