users@jaxb.java.net

RE: RE: namespace query

From: Ernst, Matthias <matthias.ernst_at_coremedia.com>
Date: Wed, 11 Apr 2007 19:48:09 +0200

> So if I managed to get package-info to compile, do you think
> this would then work? The package name odc_jaxb_gen is supplied in the call to xjc.

Yes I believe. Alternatively, outfit all relevant @XmlElement(name="...") with @XmlElement(namespace="...", name="...").

Matthias

-- 
matthias.ernst_at_coremedia.com
software architect
+49.40.32 55 87.503
CoreMedia AG
Executive Board: Sören Stamer (CEO), Dr. Klemens Kleiminger (CFO)
Supervisory Board: Prof. Dr. Joachim Schmidt (Chairman)
Trade Register: Amtsgericht Hamburg, HR B 76277
 
> -----Original Message-----
> From: Donohue Sean [mailto:SGDONOHUE_at_qinetiq.com] 
> Sent: Wednesday, April 11, 2007 2:30 PM
> To: 'users_at_jaxb.dev.java.net'
> Subject: RE: namespace query
> 
> Ah, ok.  The xml and schema were obtained on separate 
> occasions from another
> company, so I wouldn't be at all surprised if there was a 
> mismatch between
> the two.  I tried changing the elementFormDefault but that 
> didn't seem to
> fix it.
> 
> The package-info.java, I'd forgotten about that, but my 
> compiler (JBuilder)
> complains 
> "package-info.java": package annotations should be in file 
> package-info.java
> at line 8, column 1.  Which seems a little odd, and I had 
> been ignoring the
> error and running the program anyway....the file looks like:-
> // auto-generated comments
> @javax.xml.bind.annotation.XmlSchema(namespace =
> "http://www.T45PCO.com/combat_system/encyclopaedic_data",
> elementFormDefault=javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
> package odc_jaxb_gen;
> 
> 
> The OdcStoreDataT doesn't have an XmlRootElement annotation when it is
> automatically generated, but this is the only annotation I 
> have written
> myself, and I have tried specifying both an empty namespace 
> and the actual
> namespace without success.
> 
> So if I managed to get package-info to compile, do you think 
> this would then
> work?  The package name odc_jaxb_gen is supplied in the call to xjc.
> 
> Thanks,
> 
> Sean
> -----Original Message-----
> From: Ernst, Matthias [mailto:matthias.ernst_at_coremedia.com] 
> Sent: 11 April 2007 13:03
> To: users_at_jaxb.dev.java.net
> Subject: RE: namespace query
> 
> The error does indeed not match your schema. I have four 
> interpretations to
> offer:
> 
> * you compiled against a different schema (maybe with
> elementFormDefault="unqualified")
> * you missed a generated package-info.java that states the 
> namespace for all
> classes
> * you wrote the annotations yourself and forgot to add a 
> namespace to the
> XmlElement annotation on the header field
> * it's a bug in JAXB
> 
> Matthias
> -- 
> matthias.ernst_at_coremedia.com
> software architect
> +49.40.32 55 87.503
> 
> CoreMedia AG
> Executive Board: Sören Stamer (CEO), Dr. Klemens Kleiminger (CFO)
> Supervisory Board: Prof. Dr. Joachim Schmidt (Chairman)
> Trade Register: Amtsgericht Hamburg, HR B 76277
>  
> 
> > -----Original Message-----
> > From: Donohue Sean [mailto:SGDONOHUE_at_qinetiq.com] 
> > Sent: Tuesday, April 10, 2007 4:22 PM
> > To: 'users_at_jaxb.dev.java.net'
> > Subject: namespace query
> > 
> > I'm trying to unmarshal an xml file with jaxb 2.1, and 
> > getting the error:-
> > 
> > "unexpected element 
> > (uri:"http://www.T45PCO.com/combat_system/encyclopaedic_data",
> >  local:"Header"). Expected elements are<{}Header,{}Odc>, 
> > ignoring this node."
> > 
> > The code looks like:-
> > 
> > JAXBContext jc            = ...//create JAXBContext
> > 
> > Unmarshaller unmarshaller = jc.createUnmarshaller();
> > 
> > unmarsaller.setEventHandler(new DefaultValidationEventHandler());
> > 
> > Object o                  = unmarshaller.unmarshal(new 
> > FileInputStream(filename)); // fails here
> > 
> > OdcStoreDataT data        = 
> > ((JAXBElement<OdcStoreDataT>)o).getValue();
> > 
> > //OdcStoreDataT
> > 
> > @XMLRootElement(name="ODC_Store_Root", 
> > namespace=http://www.T45PCO.com/combat_system/encyclopaedic_data)
> > 
> > @XMLAccessorType(XMLAccessType.FIELD)
> > 
> > @XMLType(name="Odc_Store_Data_T", propOrder = {"header","odc"})
> > 
> > public class OdcStoreDataT{
> > 
> >    @XMLElement(name="Header", required=true)
> > 
> >    protected HeaderT header;
> > 
> >    @XMLElement(name="Odc", required=true)
> > 
> >    protected List<G600dcStoreDataT> odc;
> > 
> >    // generated get/set methods
> > 
> > }
> > 
> > I had hoped that using jaxb would be the simple solution 
> > since I'm not an XML expert.  I'm guessing its something to 
> > do with the namespace that Header belongs to.  I can marshal 
> > a new set of data out, and then read that in, but the 
> > marshaled file has inserted ns2: namespace declarations in 
> > front of Header (and standalone="yes"), so I guess that 
> > allows it to find/create the appropriate automatically 
> > generated java type, I don't know.  I can't edit all the xml 
> > files, what changes do I need to make to the schema file to 
> > fix this please?  Or do I need to somehow put the namespace 
> > in the java code? 
> > 
> > I've tried looking at the FAQ and articles, but can't find 
> > anything explaining clearly how XML namespaces are handled by 
> > jaxb.  I have the Java 6 download, which I think included 
> > jaxb 2.1(?) but not, AFAIK, the namespace-prefix sample?
> > 
> > Thanks,
> > 
> > Sean
> > 
> > xml file:-
> > 
> > <ODC_Store_Root 
> > xmlns="http://www.T45PCO.com/combat_system/encyclopaedic_data"
> >  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> > xsi:schemaLocation="http://www.T45PCO.com/combat_system/encycl
> > opaedic_data ODC_Store_Schema.xsd">
> > 
> >         <Header>
> > 
> >                 ...
> > 
> >         </Header>
> > 
> > ...
> > 
> > </ODC_Store_Root>
> > 
> > schema:-
> > 
> > <xs:schema 
> > targetNamespace="http://www.T45PCO.com/combat_system/encyclopa
> > edic_data" 
> > xmlns="http://www.T45PCO.com/combat_system/encyclopaedic_data"
> >  
> > xmlns:ed="http://www.T45PCO.com/combat_system/encyclopaedic_da
> > ta" xmlns:xs="http://www.w3.org/2001/XMLSchema" 
> > elementFormDefault="qualified" 
> > attributeFormDefault="unqualified" version="4.0" id="ODC_Store">
> > 
> >         <xs:element name="ODC_Store_Root" type="Odc_Store_Data_T">
> > 
> >         </xs:element>
> > 
> >         <xs:complexType name="Header_T">
> > 
> >             ...
> > 
> >         </xs:complexType>
> > 
> >         <xs:complexType name="Odc_Store_Data_T">
> > 
> >                 <xs:sequence>
> > 
> >                         <xs:element name="Header" type="Header_T"/>
> > 
> >                         <xs:element name="Odc" 
> > type="G60_Odc_Store_Data_T" minOccurs="0" maxOccurs="200"/>
> > 
> >                 </xs:sequence>
> > 
> >         </xs:complexType>
> > 
> > </xs:schema>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> The information contained in this E-Mail and any subsequent 
> correspondence is private and is intended solely for the intended 
> recipient(s).  The information in this communication may be 
> confidential and/or legally privileged.  Nothing in this e-mail is 
> intended to conclude a contract on behalf of QinetiQ or make QinetiQ 
> subject to any other legally binding commitments, unless the e-mail 
> contains an express statement to the contrary or incorporates 
> a formal Purchase Order.
> 
> For those other than the recipient any disclosure, copying, 
> distribution, or any action taken or omitted to be taken in reliance 
> on such information is prohibited and may be unlawful.
> 
> Emails and other electronic communication with QinetiQ may be 
> monitored and recorded for business purposes including 
> security, audit 
> and archival purposes.  Any response to this email indicates consent 
> to this.
> 
> Telephone calls to QinetiQ may be monitored or recorded for quality 
> control, security and other business purposes.
> 
> QinetiQ Limited
> Registered in England & Wales: Company Number:3796233
> Registered office: 85 Buckingham Gate, London SW1E 6PD, United Kingdom
> Trading address: Cody Technology Park, Cody Building, Ively 
> Road, Farnborough, Hampshire, GU14 0LX, United Kingdom 
> http://www.QinetiQ.com/home/legal.html
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> 
>