JAXB behaviour when unmarshalling documents with an encoding declaration

The following is against JWSDP-1.5, 1.4.2_07-b05 on XP Pro SP 2...
When I unmarshall a document using JAXB 1.0, and obtain Strings from the resulting objects, I would expect the Strings to be encoded with the character encoding specified by the text declaration. Is this a correct assumption?
Unfortunately, from the sample code (given below) I am not experiencing this behaviour. I've included the code, sample output, and the RELAX NG schema used.
Any help very welcome.
ian
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.xml.sax.InputSource;
import com.chellomedia.transcoding.Category;
import com.chellomedia.transcoding.ObjectFactory;
import com.chellomedia.transcoding.Schedule;
public class TranscoderExemplar {
     private static final String CATEGORY_NAME = "\u00bfMa\u00f1ana?";
     public static void main(String[] args) throws Exception {
          try {
               ByteArrayOutputStream os = generateSampleDocument("US-ASCII");
               inspectDocument("US-ASCII", os);
               os = generateSampleDocument("ISO-8859-1");
               inspectDocument("ISO-8859-1", os);
               os = generateSampleDocument("UTF-8");
               inspectDocument("UTF-8", os);
          } catch (FileNotFoundException e) {
               e.printStackTrace();
          } catch (JAXBException e) {
               e.printStackTrace();
          } catch (Exception e) {
               e.printStackTrace();
     private static void inspectDocument(String encoding, ByteArrayOutputStream os) throws Exception {
          byte[] b = os.toByteArray();
          System.out.println(encoding + " document byte length: " + b.length);
          InputSource is = new InputSource(new ByteArrayInputStream(b));
          is.setEncoding(encoding);
          JAXBContext context = JAXBContext.newInstance("com.chellomedia.transcoding");
          Schedule schedule = (Schedule)context.createUnmarshaller().unmarshal(is);
          context.createValidator().validate(schedule);
          List categories = schedule.getCategories();
          for (int i = 0, n = categories.size(); i < n; i++) {
               Category c = (Category)categories.get(i);
               String name = c.getName();
               System.out.println(encoding + " name string length: " + name.length());
               System.out.println(encoding + " name byte length: " + name.getBytes().length);
     private static ByteArrayOutputStream generateSampleDocument(String encoding) throws JAXBException,
          FileNotFoundException
        ObjectFactory of = new ObjectFactory();
          Schedule schedule = of.createSchedule();
          List categories = schedule.getCategories();
          Category category = of.createCategory();
          category.setId(1);
          category.setName(CATEGORY_NAME);
          categories.add(category);
          Marshaller m = of.createMarshaller();
          m.setProperty("jaxb.encoding", encoding);
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
          ByteArrayOutputStream os = new ByteArrayOutputStream();
          m.marshal(schedule, os);
          FileOutputStream fos = new FileOutputStream(encoding + "-representation.xml");
          m.marshal(schedule, fos);
          return os;
}...and the schema
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
         datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
         xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
         xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
         jaxb:extensionBindingPrefixes="xjc"
         jaxb:version="1.0">
  <jaxb:schemaBindings>
    <jaxb:package name="com.chellomedia.transcoding"/>
  </jaxb:schemaBindings>
  <start>
    <ref name="Schedule"/>
  </start>
  <define name="Schedule">
    <element name="schedule">
      <ref name="Categories"/>
      <zeroOrMore>
        <ref name="Event"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="Categories">
    <element name="categories">
      <zeroOrMore>
        <ref name="Category"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="Category">
    <element name="category">
      <attribute name="id"><data type="int"/></attribute>
      <attribute name="name"/>
      <zeroOrMore>
        <ref name="Subcategory"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="Subcategory">
    <element name="subcategory">
      <attribute name="id"/>
      <attribute name="name"/>
    </element>
  </define>
  <define name="Event">
    <element name="event">
      <attribute name="id"/>
      <attribute name="title"/>
      <attribute name="description"/>
      <attribute name="category"/>
      <attribute name="subcategory"/>
    </element>
  </define>
</grammar>...with sample output
US-ASCII document byte length: 171
US-ASCII name string length: 8
US-ASCII name byte length: 8
ISO-8859-1 document byte length: 163
ISO-8859-1 name string length: 8
ISO-8859-1 name byte length: 8
UTF-8 document byte length: 160
UTF-8 name string length: 8
UTF-8 name byte length: 8

The following is against JWSDP-1.5, 1.4.2_07-b05 on XP Pro SP 2...
When I unmarshall a document using JAXB 1.0, and obtain Strings from the resulting objects, I would expect the Strings to be encoded with the character encoding specified by the text declaration. Is this a correct assumption?
Unfortunately, from the sample code (given below) I am not experiencing this behaviour. I've included the code, sample output, and the RELAX NG schema used.
Any help very welcome.
ian
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.xml.sax.InputSource;
import com.chellomedia.transcoding.Category;
import com.chellomedia.transcoding.ObjectFactory;
import com.chellomedia.transcoding.Schedule;
public class TranscoderExemplar {
     private static final String CATEGORY_NAME = "\u00bfMa\u00f1ana?";
     public static void main(String[] args) throws Exception {
          try {
               ByteArrayOutputStream os = generateSampleDocument("US-ASCII");
               inspectDocument("US-ASCII", os);
               os = generateSampleDocument("ISO-8859-1");
               inspectDocument("ISO-8859-1", os);
               os = generateSampleDocument("UTF-8");
               inspectDocument("UTF-8", os);
          } catch (FileNotFoundException e) {
               e.printStackTrace();
          } catch (JAXBException e) {
               e.printStackTrace();
          } catch (Exception e) {
               e.printStackTrace();
     private static void inspectDocument(String encoding, ByteArrayOutputStream os) throws Exception {
          byte[] b = os.toByteArray();
          System.out.println(encoding + " document byte length: " + b.length);
          InputSource is = new InputSource(new ByteArrayInputStream(b));
          is.setEncoding(encoding);
          JAXBContext context = JAXBContext.newInstance("com.chellomedia.transcoding");
          Schedule schedule = (Schedule)context.createUnmarshaller().unmarshal(is);
          context.createValidator().validate(schedule);
          List categories = schedule.getCategories();
          for (int i = 0, n = categories.size(); i < n; i++) {
               Category c = (Category)categories.get(i);
               String name = c.getName();
               System.out.println(encoding + " name string length: " + name.length());
               System.out.println(encoding + " name byte length: " + name.getBytes().length);
     private static ByteArrayOutputStream generateSampleDocument(String encoding) throws JAXBException,
          FileNotFoundException
        ObjectFactory of = new ObjectFactory();
          Schedule schedule = of.createSchedule();
          List categories = schedule.getCategories();
          Category category = of.createCategory();
          category.setId(1);
          category.setName(CATEGORY_NAME);
          categories.add(category);
          Marshaller m = of.createMarshaller();
          m.setProperty("jaxb.encoding", encoding);
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
          ByteArrayOutputStream os = new ByteArrayOutputStream();
          m.marshal(schedule, os);
          FileOutputStream fos = new FileOutputStream(encoding + "-representation.xml");
          m.marshal(schedule, fos);
          return os;
}...and the schema
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
         datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
         xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
         xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
         jaxb:extensionBindingPrefixes="xjc"
         jaxb:version="1.0">
  <jaxb:schemaBindings>
    <jaxb:package name="com.chellomedia.transcoding"/>
  </jaxb:schemaBindings>
  <start>
    <ref name="Schedule"/>
  </start>
  <define name="Schedule">
    <element name="schedule">
      <ref name="Categories"/>
      <zeroOrMore>
        <ref name="Event"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="Categories">
    <element name="categories">
      <zeroOrMore>
        <ref name="Category"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="Category">
    <element name="category">
      <attribute name="id"><data type="int"/></attribute>
      <attribute name="name"/>
      <zeroOrMore>
        <ref name="Subcategory"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="Subcategory">
    <element name="subcategory">
      <attribute name="id"/>
      <attribute name="name"/>
    </element>
  </define>
  <define name="Event">
    <element name="event">
      <attribute name="id"/>
      <attribute name="title"/>
      <attribute name="description"/>
      <attribute name="category"/>
      <attribute name="subcategory"/>
    </element>
  </define>
</grammar>...with sample output
US-ASCII document byte length: 171
US-ASCII name string length: 8
US-ASCII name byte length: 8
ISO-8859-1 document byte length: 163
ISO-8859-1 name string length: 8
ISO-8859-1 name byte length: 8
UTF-8 document byte length: 160
UTF-8 name string length: 8
UTF-8 name byte length: 8

Similar Messages

  • Error when opening document with ECL control: INVALID_DATA

    Hi Gurus,
    I've tried to search the net for this problem but could not find anything and I'm stuck now.
    Description:
    we're using ECL to view attached documents (to POs etc.) which are stored through ArchiveLink on the content repository.
    when we try to open this document, time-to-time we get following error:
    Error when opening document with ECL control: INVALID_DATA
    Message no. SDV004
    by time-to-time I mean that when we try to open same attachment again it opens successfully (sometimes we need to re-open it 3-4 times to get it)
    what we've tried is to enlarge timeout for HTTP protocol (tx SMICM, from former 30 to actual 60) but only effect we got is that we're waiting for the error longer time
    It will be really great if anybody of you guys can give me an advice where the problem can be or where should I look and what to check
    Thanks,
    David

    Hi Christoph,
    thanks for tip, unfortunately this was already flagged, currently settings are:
    for Display Settings:
    yes - include ECL control
    use HTML control
    empty - maximum viewer wait time
    (do you think that setting some value for this could help)
    yes - deactivate generic object services in viewer
    no - doc display as dialog box
    yes - deactivate data provider cache
    Storage Settings:
    yes - always copy document class from document type
    yes - permit multiple assignment
    Thanks,
    David

  • SAP DMS : Error when opening document with ECL control: INVALID_DATA

    We are receiving following error while try to view .FAX file through SAP Document viewer
    "2D viewer - Unable to opend Document"
    "Error when opening document with ECL control: INVALID_DATA"
    Appreciate your quick effort.
    Thanks,
    Sam.

    Yes, We have checked in both ways, I have also followed other threads on the same issue
    But not able to find the solution for the issue. We are facing the issue when we are using files scannned by Kodak Scanner i1420 in tiff format.
    But If I will attach any other tiff files from directory then It can viewed through SAP Document Viewer.
    I appreaciate your help in this regards.
    Thanks,
    Sam,

  • DI API Problem when generating documents with Item with BOM "Template"

    I have a web application we've been using for years, we created an interface to select with child items from the BOM template you want to add, just like in SAP when you add this items in the document lines.
    For some reason through the DI it automatically adds again this items additionally to the ones I selected, is there a way to change this behaviour?
    I checked the Document.Lines.Count property when I add the item and after I add it in SAP and I get the total items that I put in the first place, but in the final document in SAP its completly different

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using SAPbobsCOM;
    namespace SAP_Error_Demo
        class Test
            public static void Execute()
                try
                    Company company = new Company
                                              DbServerType = BoDataServerTypes.dst_MSSQL2005,
                                              Server = ".",
                                              UseTrusted = true,
                                              CompanyDB = "ESHOPS",
                                              UserName = "manager",
                                              Password = "manager"
                    int returnValue = company.Connect();
                    int errCode;
                    string errMsg;
                    if (!returnValue.Equals(0))
                        company.GetLastError(out errCode, out errMsg);
                        MessageBox.Show(string.Format("Connection Error: {0}", errMsg));
                        return;
                    Documents document = (Documents) company.GetBusinessObject(BoObjectTypes.oOrders);
                    document.CardCode = "yuval";
                    document.Series = 2;
                    document.DocDate = DateTime.Now;
                    document.DocDueDate = DateTime.Now.AddMonths(1);
                    document.DocCurrency = "$";
                    Document_Lines lines = document.Lines;
                    lines.ItemCode = "21725";
                    lines.Quantity = 1;
                    lines.UnitPrice = 54.021;
                    lines.Price = 54.021;
                    lines.VatGroup = "V1";
                    returnValue = document.Add();
                    if (!returnValue.Equals(0))
                        company.GetLastError(out errCode, out errMsg);
                        MessageBox.Show(string.Format("An error ocurred when adding document: {0}", errMsg));
                        return;
                    MessageBox.Show("Document was generated successfully");
                    company.Disconnect();
                catch (Exception ex)
                    MessageBox.Show(string.Format("Error: {0}", ex.Message));

  • Pop up message when saving document with document set

    Hi
    I want to display a pop up message when a user saves a document of a particular Content Type in a document set.
    How can this be done ?
    Thanks

    Hi,
    According to your post, my understanding is that you wanted to pop up a message when saving document.
    To achieve it, you should custom the edit form page.
    You can use the SharePoint Designer
    to customize the behavior of the "save" button.
    You should add the "onclick" method to the submit button, and put your JavaScript there.
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/9d830f96-693a-438d-a5c8-005d1e86b578/how-to-show-a-popup-box-before-saving-properties-for-a-document-in-document-library?forum=sharepointdevelopmentlegacy
    You can also use the event receiver, when the files have been uploaded or edited to call the event receiver to open a pop up dialog.
    Thanks,
    Jason
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Jason Guo
    TechNet Community Support

  • Very very weird webcam behaviour when recording movie with quicktime????!!!

    Ok tried today playing about with photobooth, and after a while it bugged, camera not recongnised open quicktime and tried to record a movie and there was the little icon saying there was no camera. Anyway, rebooted the computer photobooth ok but slow, threw preference files relaunched fine. tried quicktime, and the image is reversedright is left and left is right how can i fix that???? Thank you for input.
    David

    I think I found the solution. Some further digging revealed that I did not have as previously assumed the latest driver for my graphics card installed. I was mislead because the manufacturer (Dell) did provide some updates, but not all of them (none in the past two years to be exact). I grabbed the newest driver kit from the ATI website and installed it. Strangely, the installer produced several errors and I get another error message at startup, but I think only the control software was affected and not the driver itself.
    After some first tests, QuickTime movies behave as expected, the preview renders are working again and the crashes on exit are also gone. Yay!
    Strange how much trouble a driver which is otherwise working perfectly can cause.

  • Open links to documents with Office Web Apps

    Hi,
    I am trying to configure SharePoint 2013 and Office Web Apps Server 2013 in a Multi Tenant environment for a client that has specific requirements when it comes to document handling.
    They have a number of document libraries where the majority of their user base will only be able to view the documents it contains using the Office Web Apps Viewer and not be able to download it or access it using the local client (Their SharePoint Group
    membership has View Only Permission on the Site).  We see exactly this behaviour when the documents are accessed from within the Document Library App or associated Web Part but not if the documents are linked to from elsewhere within the Site, e.g. The
    library in question is being used to store newsletters and they want to be able to insert links to the latest newsletter in an Announcement or Newsfeed item. As it stands these links present the user with an access request page or with Read permissions on
    their SharePoint Group a browser download dialog.
    My initial searches have so far brought up a suggestion to
    doing the reverse in search which might be promising and updating workflows to modify the url provided in an email to the appropriate wopi url which in my mind suggests a user manual.  Something that would work automatically on at least the
    Site, better Site Collection or ideally Site Subscription level is what I am looking for as our clients users are far from technically minded and a lookup table of file extensions and how to construct the url is out of the question.
    Thanks in advance for any help or advice provided.
    Matt

    Hi,
    I am trying to configure SharePoint 2013 and Office Web Apps Server 2013 in a Multi Tenant environment for a client that has specific requirements when it comes to document handling.
    They have a number of document libraries where the majority of their user base will only be able to view the documents it contains using the Office Web Apps Viewer and not be able to download it or access it using the local client (Their SharePoint Group
    membership has View Only Permission on the Site).  We see exactly this behaviour when the documents are accessed from within the Document Library App or associated Web Part but not if the documents are linked to from elsewhere within the Site, e.g. The
    library in question is being used to store newsletters and they want to be able to insert links to the latest newsletter in an Announcement or Newsfeed item. As it stands these links present the user with an access request page or with Read permissions on
    their SharePoint Group a browser download dialog.
    My initial searches have so far brought up a suggestion to
    doing the reverse in search which might be promising and updating workflows to modify the url provided in an email to the appropriate wopi url which in my mind suggests a user manual.  Something that would work automatically on at least the
    Site, better Site Collection or ideally Site Subscription level is what I am looking for as our clients users are far from technically minded and a lookup table of file extensions and how to construct the url is out of the question.
    Thanks in advance for any help or advice provided.
    Matt

  • Cannot share documents with few users in one way trusted domain

    Hello
    I am running in a wiered issue. I setup people picker in SP 2013 foundation version to lookup the user from one way trusted domains after which I started getting all the users from that domain in my intranet. I can also share or modify the permission of
    users being administrator. However when I try to add 2 specific users as site collection administrator or try sharing a document, I get error.
    I can lookup their name but when I try changing their permission or share document with them, I get error. It's wiered because it is only with this two users. there is no difference from Active Directory point of view between these and other users. Please
    help or suggest some trouble shooting steps.
    Regards,
    Hardik Bhilota.

    Hi Hardik,
    What was the error message when sharing documents with the two users?
    Please also check the ULS log for detailed error message which is located at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\LOGS.
    What is the permission of the two users in SharePoint site? Can they access the site?
    Please also run the two commands below to see if the issue still occurs:
    First, on every front-end Web server on a farm run this command:
    STSADM.exe -o setapppassword -password key
    Second, on a front-end Web server run this command:
    STSADM.exe -o setproperty -pn peoplepicker-searchadforests -pv domain:DnsName,user,password -url http:// webapp
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • Saving documents with similar file names

    When saving documents with similar file names, I used to be able to hit save as button and go to the file folder I wish to use. I could then click an existing file in the folder to draw in the name and then just modify it slightly to create the new name.
    In Reader DC I get an error saying this is a read only file an can not be saved.  I can save the file if I use a different file name but then I have to go in and rename the file. i.e. if I have a weakly report that I save, I may have the file name "Installerspayroll.we.04.25.15.pdf."
    I used to be able to click on the existing file name to bring it into the name box and then just change the date. The updated version is not allowing me to do that, creating more work.

    I thought you were referring to an admin account within the Adobe program. I am an admin on the machine I am signed into and using while having these problems
    Thank you for this opportunity to share our expertise,
    Michael Mallary
    Treasurer
    Mallary Carpet & Flooring, Inc.
    410-766-6992
    www.mallarycarpet.com<http://www.mallarycarpet.com>
    Earning your unsolicited referrals
    is our number one priority

  • Errors when unmarshalling with JAXB

    Am getting an error when unmarshalling an xml file .....
    javax.xml.bind.UnmarshalException
    - with linked exception:
    [org.xml.sax.SAXParseException: unexpected root element comment]
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:298)
         at com.sun.xml.bind.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:146)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:131)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:136)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:145)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:163)
         at PurchaseOrderClient.main(PurchaseOrderClient.java:18)
    My .xsd file is like ----
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="comment" type="xsd:string"/>
    </xsd:schema>
    and .xml file is ----
    <?xml version="1.0" encoding="UTF-8"?>
    <!--Sample XML file generated by XMLSpy v2006 sp2 U (http://www.altova.com)-->
    <comment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Projects\marshall\sample.xsd">String</comment>
    Am running through stand alone java code as below ---
    import generated.*;
    import java.io.File;
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.Unmarshaller;
    public class PurchaseOrderClient{
         public static void main(String[] args) {
              try{               
              JAXBContext jc = JAXBContext.newInstance("generated");
              Unmarshaller unmarshaller = jc.createUnmarshaller();          
              Object po = null;     
              po = (Name)unmarshaller.unmarshal(new File("sample.xml"));     
              System.out.println(po.toString());                    
              catch(Exception e)
                   e.printStackTrace();
    plz help me out.
    Aditya.

    Am getting an error when unmarshalling an xml file .....
    javax.xml.bind.UnmarshalException
    - with linked exception:
    [org.xml.sax.SAXParseException: unexpected root element comment]
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:298)
         at com.sun.xml.bind.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:146)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:131)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:136)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:145)
         at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:163)
         at PurchaseOrderClient.main(PurchaseOrderClient.java:18)
    My .xsd file is like ----
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="comment" type="xsd:string"/>
    </xsd:schema>
    and .xml file is ----
    <?xml version="1.0" encoding="UTF-8"?>
    <!--Sample XML file generated by XMLSpy v2006 sp2 U (http://www.altova.com)-->
    <comment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Projects\marshall\sample.xsd">String</comment>
    Am running through stand alone java code as below ---
    import generated.*;
    import java.io.File;
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.Unmarshaller;
    public class PurchaseOrderClient{
         public static void main(String[] args) {
              try{               
              JAXBContext jc = JAXBContext.newInstance("generated");
              Unmarshaller unmarshaller = jc.createUnmarshaller();          
              Object po = null;     
              po = (Name)unmarshaller.unmarshal(new File("sample.xml"));     
              System.out.println(po.toString());                    
              catch(Exception e)
                   e.printStackTrace();
    plz help me out.
    Aditya.

  • JAXB unmarshalling elements with xs:type explicitly set

    I am working with XML content where the XSD defines an element as being of a complexType (say "ParentType") but the content explicitly sets the element's xs:type attribute to an extension of that complexType (say "ChildType").
    As far as I can tell the XML is valid, but JAXB issues the following when unmarshalling:
    DefaultValidationEventHandler: [ERROR]: Unexpected element {}:child1
    javax.xml.bind.UnmarshalException: Unexpected element {}:child1
    Where <child1> is added via the extension.
    Is this a problem with JAXB or my XSD?
    (XSD and XML enclosed below)
    XSD ------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:complexType name="ParentType">
    <xs:sequence>
    <xs:element name="parent1" type="xs:string"/>
    <xs:element name="parent2" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="ChildType">
    <xs:complexContent>
    <xs:extension base="ParentType">
    <xs:sequence>
    <xs:element name="child1" type="xs:string"/>
    </xs:sequence>
    </xs:extension>
    </xs:complexContent>
    </xs:complexType>
    <xs:element name="root">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="child" type="ParentType"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    XML -----------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="problem.xsd">
    <child xsi:type="ChildType">
    <parent1/>
    <parent2/>
    <child1/>
    </child>
    </root>

    JAXB doesn't handle OO schema design. I tried to do something similar where I defined a type called base and then defined that my document contained 1 or more base elements. Then I tried to unmarshall a document that contained elements that were of types extending from base. I ended up with the same issue.
    It seems that when the xjc compiler defines the classes it isn't smart enough to realize the element defined as parent could also contain a child element since child extends parent. Your XSD and XML are valid.
    I would think that JAXB should identify that because there is a type the extends the defined type, that an element of the sub-type might be subsituted i.e. check the actual type of the element in the XML before attempting to unmarshall it as the default type. It doesn't do that. I am not sure if this is as desinged, or a flaw in the implementation.

  • I saved a word file onto my imac.  when i go to open file in documents with pages the file is grey and unable to open.  the workable files are highlighted in bold.  is there a way to open this file????

    i saved a word file onto my imac.  when i go to open file in documents with pages the file is grey and unable to open.  the workable files are highlighted in bold.  is there a way to open this file????

    THis is safe for Mac's? Sorry, I have just never heard of this site before.
    And there are literally tens of thousands of sites of which I've not heard, too. Not this one.
    It's legit. There are lots of links in Apple Support Communities to the LibreOffice web site, as well as others that are legitimate open-source developers of options to buying MS Office, such as NeoOffice and OpenOffice. I have Open Office installed on one of my older Macs that can't run Office 2011 and it is rock-solid.
    I've been here too long to start posting bogus urls now.

  • How to export a PDF to a word document? at the moment it came up with "The encoding (CMap) specified by a font is missing ????? what can I do?  thanks

    How to export a PDF to a word document? at the moment it came up with "The encoding (CMap) specified by a font is missing ????? what can I do?  thanks

    Hi frenchiem,
    This is due to the PDF file cannot display the original fonts. To fix it, creator should create the PDF file with the embed font option enabled. Thus, user can open the file on any platform with the same layout. Or the Acrobat product can display them after you install the appropriate font support package on the client side.
    Regards,
    Rave

  • Is there a format for a file that I can use for attaching a one page document with photos embedded that will open in everyone's email automatically?   I've tried PDF and Word, but worked only in Mail.  Lost formatting when just copied and pasted in email.

    Is there a format for a file that I can use for attaching a one page document with photos embedded that will open in everyone's email automatically?   I've tried PDF and Word, but PDF worked only in Mail.  Word worked in nothing.  I also tried copying and pasting the document but lost all formatting when just copied and pasted in email.  Is there a way to do this?

    Are you sure PDF won't work? It should as what you're trying to do is pretty much what it is designed for (PDF - Portable Document Format). On a Mac anywone who receives the file should be able to see it in all its page layout glory by using the app Preview or Adobe Reader. Same on a PC, the file should be viewable as a PDF file using Adobe Reader and probably some other viewer (don't use PCs so not sure what other apps).
    What application are you creating the file in and are you sure you're exporting it correctly in PDF format, fonts and images embedded?

  • Strange behavior when creating a document with an "html" node

    A strange thing is happening here. I'm using the javax.xml.transform.Transformer to save some XML documents. I can create documents with any arbitrary DOM tree I want, but if I have the root node have a name of "html". somehow the Transformer decides to apply its own HTML rules and handles it differently from all other document types. The problem is that its html-specific rules are not what I want. Specifically, it is doing things like outputting <br> instead of
    , putting in meta-equiv tags that I don't want, etc. This is all bad because I'm not writing HTML. I'm writing carrier-specific mobile xhtml documents and I don't want the javax.xml.transform.Transformer to be "helping" me out any.
    There must be some way to get this under control. Can anyone advise me?
    Thanks

    I think I solved the problem: I need to put this line in:
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");and that does the trick, and forces it to not get fancy when it's outputting <html>. I suppose there's a way of setting that in the TransformerFactory so I don't have to set it in every individual transformer I create but that's a minor issue.

Maybe you are looking for

  • New to solaris what should I be downloading solaris 10 or opensolaris?

    well I have some experience with redhat but want to learn solaris as, well I really will never be able to get a linux/unix position if I only know one. hmm so I started looking around and got confused by the many versions now available of solaris. so

  • Macbook Pro won't boot! Deep sleep?  HELP!

    Hi, Recently I started to experience problems with my Macbook Pro. When I'd boot into OSX, the system's screen would go completely blank after a couple of minutes of use. I booted from a CD and repaired the disk. I then booted my XP Pro partition on

  • How do you create outlines from strokes in cs5

    how do you create outlines from strokes in cs5

  • AD-41 headset volume regulation sensitivity !

    Hi! I own Nokia 3250 and what's really annoying me is the headset's volume adjustment. It works terrible ! The sensitivity of buttons is so high that it's very difficult to change volume only one level up or down. I don't know if it applies only to t

  • HighwayVIE​W Version 4.2.2 & Allen Bradley PLC-2

    Does anyone have any experience with this software? I am trying to make the transition from Lookout Protocol drivers (AB PLC-2 object) to using Highway VIEW Version 4.2.2. I have over 1800 tags. (I think I can do most of this using excel with the tag