JAXB 2 validation?

Hi,
Just right now I installed JAXB 2.0.
Although the Java Web Services Tutorial for JWSDP v2.0 p33
mentions a "Unmarshal Validate Example", this is
not included in the samples dir anymore.
Furthermore the Validator interface as well as
the JAXBContext.setValidating() function is depricated.
Calling this function anyway yields an exception ("not supported").
How can I do validation in JAXB 2.0?
Have fun,
Klaus

I ran into the same thing, and it seems they refactored the validation stuff into javax.xml.validation. Below is an example of a method I made to marshal an XJC-generated object to a DOMSource. Note that despite the method being for marshalling the validation is still on-demand, not on-marshal. Also note that the Validator class used is javax.xml.validation.Validator. The validate() method supports more advanced methods of retrieving the output but I am keeping it simple since I am new to JAXB and not trying to make my life complicated.
     public static DOMSource marshalToDOMSource(Object xmlObj, boolean doValidate)
          throws Exception{
          JAXBContext context = JAXBContext.newInstance("com.tmg.emkt.xml.bind");
          Marshaller marshaller = context.createMarshaller();
          SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
          Schema schema = sf.newSchema(new URL(schemaURL));
          String elementName = xmlObj.getClass().getName();
          elementName = elementName.substring(elementName.lastIndexOf(".")+1);
          marshaller.setProperty("jaxb.formatted.output", true);
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          dbf.setNamespaceAware(true);
          DocumentBuilder db = dbf.newDocumentBuilder();
          Document doc = db.newDocument();
          marshaller.marshal(xmlObj,doc);
          DOMSource source = new DOMSource(doc);
          if (doValidate){
               javax.xml.validation.Validator validator = schema.newValidator();
               validator.validate(source);
          return source;
     }

Similar Messages

  • JAXB Validation Error

    Hi,
    Iam using JAXB. I get an validation error. When i try to marshal an object to XML. The code is simple as shown below
    1. Container.xsd
    <?xml version="1.0" encoding="UTF-8"?>
    <schema targetNamespace="http://agi.com"
    xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://agi.com"
    elementFormDefault="qualified">
    <complexType name="ContainerType" abstract="true">
    <sequence>
    <choice>
    <element name="File" type="anyType" />
    <element name="Pen" type="anyType" />
    </choice>
    </sequence>
    </complexType>
    <element name="Container" type="tns:ContainerType" abstract="true" />
    </schema>
    2. Holder.xsd
    <?xml version="1.0" encoding="UTF-8"?>
    <schema targetNamespace="http://agi.com"
    xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://agi.com"
    elementFormDefault="qualified">
    <include schemaLocation="Container.xsd"></include>
    <complexType name="HolderType">
    <complexContent>
    <restriction base="tns:ContainerType">
    <sequence>
    <choice>
    <element name="File">
    <complexType>
    <sequence>
    <element name="FileName"
    type="string">
    </element>
    <element name="Capacity"
    type="integer">
    </element>
    </sequence>
    </complexType>
    </element>
    <element name="Pen">
    <complexType>
    <sequence>
    <element name="Make"
    type="string">
    </element>
    </sequence>
    </complexType>
    </element>
    </choice>
    </sequence>
    </restriction>
    </complexContent>
    </complexType>
    <element name="Holder" type="tns:HolderType"></element>
    </schema>
    Main.java
    package test.client;
    import java.io.PrintWriter;
    import java.io.StringWriter;
    import java.math.BigInteger;
    import java.util.List;
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.Marshaller;
    import javax.xml.bind.Unmarshaller;
    import javax.xml.bind.Validator;
    import test.vo.AnyType;
    import test.vo.Holder;
    import test.vo.ObjectFactory;
    import test.vo.HolderType.FileType;
    import test.vo.HolderType.PenType;
    import com.sun.xml.bind.StringInputStream;
    public class Main {
    public static void main(String s[]) throws Exception{
    JAXBContext ctx = JAXBContext.newInstance("test.vo" );
    ObjectFactory obj = new ObjectFactory();
    Holder input = obj.createHolder();
    FileType file = obj.createHolderTypeFileType();
    file.setCapacity( BigInteger.valueOf(35) );
    file.setFileName("Accounts");
    AnyType any = obj.createAnyType();
    List lst = any.getContent();
    lst.add(file);
    input.setFile(any);
    Marshaller marsh = ctx.createMarshaller();
    marsh.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
    new Boolean(true));
    marsh.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
    "http://agi.com");
    Validator validator = ctx.createValidator();
    validator.validate(input);
    StringWriter sw = new StringWriter();
    marsh.marshal(input, new PrintWriter(sw) );
    StringBuffer sb = sw.getBuffer();
    System.out.println(sb.toString() );
    This throws the following exception
    DefaultValidationEventHandler: [ERROR]: tag name "test.vo.AnyType" is not allowed. Possible tag names are: <test.vo.HolderType.FileType>
    Location: obj: test.vo.impl.HolderImpl@1cd8669
    Exception in thread "main" com.sun.xml.bind.serializer.AbortSerializationException: tag name "test.vo.AnyType" is not allowed. Possible tag names are: <test.vo.HolderType.FileType>
    at test.vo.impl.runtime.ValidationContext.reportEvent(ValidationContext.java:199)
    at test.vo.impl.runtime.ValidationContext.reportEvent(ValidationContext.java:166)
    at test.vo.impl.runtime.MSVValidator.childAsElementBody(MSVValidator.java:336)
    at test.vo.impl.runtime.MSVValidator.childAsBody(MSVValidator.java:292)
    at test.vo.impl.ContainerTypeImpl.serializeBody(ContainerTypeImpl.java:52)
    at test.vo.impl.HolderTypeImpl.serializeBody(HolderTypeImpl.java:30)
    at test.vo.impl.HolderImpl.serializeBody(HolderImpl.java:43)
    at test.vo.impl.runtime.MSVValidator._validate(MSVValidator.java:102)
    at test.vo.impl.runtime.MSVValidator.validate(MSVValidator.java:77)
    at test.vo.impl.runtime.ValidationContext.validate(ValidationContext.java:75)
    at test.vo.impl.runtime.ValidatorImpl.validate(ValidatorImpl.java:121)
    at test.vo.impl.runtime.ValidatorImpl.validate(ValidatorImpl.java:104)
    at test.client.Main.main(Main.java:63)
    However if i commentout the validation it works fine yeilding the
    following result
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Holder xsi:schemaLocation="http://agi.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://agi.com">
    <File>
    <FileName>Accounts</FileName>
    <Capacity>35</Capacity>
    </File>
    </Holder>
    Which look good conforming to the schema above
    It willbe helpful if someout could point out the mistake iam doing
    Please help
    Regards
    Agilan Palani

    I changed the code
    marsh.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,"http://agi.com Holder.xsd");
    to
    marsh.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,"http://agi.com E:/Agilan/Holder.xsd");
    But still the same error.
    I have validated the generated xml using XMLObjective. It says the generated xml is valid against the schema.
    I really dont know why the JAXB validation fails?
    Please help

  • Urgent Help on JAXB Validation - Please Help

    I have an application that needs validation before marshalling a content tree. If the tree is not valid, I need to marshall the tree and look at the problem in the XML file itself.
    If it's a valid XML file, then continue as usual...
    These is the pseudo code.. But don't know if I can implement it with JAXB or not....And how to implement it..
    populate XML tree
    check if the tree is valid or not
    if it is valid continue processing
    if not valid, marshall the tree into an XML file and analyze the
    problem
    Any input is welcome...
    Thanks in advance..

    svenkatesh s, thanks for your reply. In addition to your suggestion,
    I found this method:
    public class ValidationHelper implements ValidationEventHandler {
    public boolean handleEvent(ValidationEvent arg0) {
         System.out.println("The message is: " + arg0.getMessage());
         System.out.println("The severity is: " + arg0.getSeverity());
         ValidationEventLocator locator = arg0.getLocator();
         System.out.println("The column number: " + locator.getColumnNumber());
         System.out.println("The line number: " + locator.getLineNumber());
              Node nd = locator.getNode();
              log.write(Logger.LOG_INFO, "The node: " + nd);
              String st = nd.getNodeName();
              log.write(Logger.LOG_INFO, "Node Name " + st);
              String stt = nd.getNodeValue();
              log.write(Logger.LOG_INFO, "Node Value: " + stt);
              return true;
    I noticed that Node is null, but it might be a test data problem...

  • JAXB - validation problem with regexp bound int type

    Hello everyone,
    I have a simpleType defined in my schema as follows:
    <xs:simpleType name="BasketRetentionType">
    <xs:restriction base="xs:int">
    <xs:totalDigits value="10"/>
    <xs:pattern value="(0|[1-9][0-9]*)"/>
    </xs:restriction>
    </xs:simpleType>
    '020' and '+20' values are not allowed (as I need it to be), but I've got them validated by JAXB.
    I wonder if there's anyone who can confirm this or shall I add any java code I may have ignored.
    I'm working with :
    - OS : Microsoft Windows NT v4.0 Serv.Pack6
    - java : j2sdk1.4.1_05
    - jaxb : jwsdp-1.3
    Thanks
    L. Chiartano

    Try this pattern: +\\d*|\\d*
    Also take a look at:
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
    I don't know if it's \\d or \d, trail and error.
    bye ki

  • JAXB Validation

    Using JAXB I have generated and compiled classes for my schema and everything appears ok.
    I can create new objects using the ObjectFactory and I am able to validate those objects.
    If an object is invalid I know how to inspect the resultant ValidationEvent and determine why the error occurred.
    However, although I am able to determine the cause of a validation failure, how can I determine - and this is the important bit for me - without prior knowledge of the schema, how to resolve this failure.
    For example:
    My schema allows me to create Apple objects. Each apple must have a type and that type must be either 'one ' or 'two'
    Therefore:
    valid - <apple><type>one<type></apple>
    invalid - <apple><type>three<type></apple>
    invalid:- <apple></apple>
    The following bit of code will create a valid apple object:
    ObjectFactory objFactory = new ObjectFactory();
    AppleImpl apple = (AppleImpl)objFactory.createApple();
    apple.setType("one);
    However, without calling setType("one") my apple object will be invalid.
    Examining that ValidationEvent returned from validating the object I can determine what is wrong with the object.
    ValidationEvent event;
    event.getNode() -> null
    event.getLocator().getSeverity() -> 1
    event.getLocator().getColumnNumber() -> 1
    event.getLocator().getLineNumber() -> -1
    event.getLocator().getOffset( ) -> -1
    event.getLocator().getURL( ) -> null
    event.getLocator().getObject( ) -> Apple@d1c65d
    event.getLocator().toString( ) -> So now I know the problem is with the type field.
    However, without prior knowledge of the schema and without knowing the type field must be set to 'one' or 'two' then how can I determine this? What methods are available in JAXB to determine what values I can set type to?
    Or is this beyond the scope of JAXB?
    (also posted in Java Technologies for Web Services -wasn't sure of best place for it)

    Many thanks for your response. However, if you have any code snippets/examples relating I go from JAXB to look at DOM validation that 'd be useful. In fact, anything at all as to where I should start looking.
    Hi ,
    Did u find any solution,please let me know.

  • JAXB Validation without a Schema

    Part of the benefit of JAXB is that a schema is not required; annotating Java classes alone allows for XML serialization/deserialization. With the deprecation of the Unmarshaller.setValidating() in favor of the unmarshaller.setSchema() method, however, it seems that validation is only available when an XSD is present. Is there another way to validate XML during unmarshalling without a physical schema file?

    Unmarshaller#setValidating(boolean) is deprecated as of 2.0 [1].
    This method throws an UnsupportedOperationException in the UnmarshallerImpl class within sun's v2 jaxb implementation.
    [1] https://jaxb.dev.java.net/nonav/jaxb20-pfd/api/javax/xml/bind/Unmarshaller.html#setValidating(boolean)

  • JAXB validation error with sample applications

    Hi,
    When trying to generate the java from po.xsd in the first example I get two compile errors in the result :
    "PurchaseOrderImpl.java": Error #: 454 : class {deleted root}.generated.impl.PurchaseOrderImpl should be declared abstract; it does not define method validateThis() in interface javax.xml.bind.Element at line 11, column 8
    "CommentImpl.java": Error #: 454 : class {deleted root}.generated.impl.CommentImpl should be declared abstract; it does not define method validateThis() in interface javax.xml.bind.Element at line 11, column 8
    where {deleted root} represents parent packages in our source tree.
    Anyone else seen this?
    I'm using Ant1.51 to kick off the build, with the patch referred to in Apache bug 14640. (http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14640)
    The target to do the build is defined as follows :-
    <target name="schema" depends="init"
    description="Compile schema">
    <echo message="Compiling the schema..."/>
    <jaxb destDir="${src}"
    readOnly="true"
    strictValidation="true"
    xjcjar="${JAXB_HOME}\lib\jaxb-xjc.jar">
    <schemas dir="${basedir}" includes="po.xsd"/>
    <targetPackageMapper type="regexp"
    from="(.*)\.xsd" to="{deleted root}.generated"/>
    </jaxb>
    </target>
    where ${src} is the root of the source tree and ${basedir} is the parent directory of "generated", containing the build.xml.

    More precisely, this is a compile time error for the generated Java classes. The methods
    void invalidate()
    void validate()
    void validate(Validator v)
    void validateThis()
    defined in
    com.sun.xml.bind.validator.ValidatableObject
    are not being built for
    generated.impl/XTypeImpl.java
    which extends
    generated.impl/XImpl.java

  • Detailed error messages from jaxb validation

    Hi,
    I am developing an application that uses jaxb. When I validate an XML documenmt I am creating using the generated code, and validate the object the error message I get is not very detailed.
    I have a type that containes three elements. One of the elements is an enumeration. If i put an invalid value into that element in the type, and validate, the validation says :
    javax.xml.bind.ValidationException - with linked exception: [com.sun.xml.bind.serializer.AbortSerializationException: the value is not a member of the enumeration.]
    It does not mention the element name, or the possible values of the enumration or the value set.
    If I validate in oxygen XML or another tool it tells me the name of the element and possible values.
    How do I do this in my code?
    I have already made my own validator from a copy of DefaultValidationHandler and run that, but in that code I only get a handle to the top level complexType.
    How do I get the information about which child element relates to the error message? Or is there another strategy to get this info ?
    Thanks
    Paul.

    I am one of the many getting this error. In my case I am trying to connect to my wife. She is on a brand new intel macbook. I am on a iMac G5. My error message is below and doesn't seem to have the same issues referenced by the earlier user. Thoughts?
    Video Conference Error Report:
    24.600844 @:0 type=4 (00000000/2)
    [VCSIP_INVITEERROR]
    [19]
    24.600695 @SIP/SIP.c:2437 type=4 (900A0015/2)
    [SIPConnectIPPort failed]
    Video Conference Support Report:
    24.101248 @SIP/Transport.c:1218 type=1 (00000000/0)
    [INVITE sip:[email protected] SIP/2.0
    Via: SIP/2.0/UDP 192.168.15.100;branch=z9hG4bK26fc92013a67f90a
    Max-Forwards: 70
    To: "u0" <sip:[email protected]>
    From: "[email protected]" <sip:[email protected]>;tag=832276631
    Call-ID: 39f2e40a-16bf-11db-8b4f-d21f408913c4@lip
    CSeq: 1 INVITE
    Contact: <sip:[email protected]>;isfocus
    User-Agent: Viceroy 1.2
    Content-Type: application/sdp
    Content-Length: 532
    v=0
    o=graeme_hepworth 0 0 IN IP4 192.168.15.100
    s=[email protected]
    c=IN IP4 192.168.15.100
    b=AS:2147483647
    t=0 0
    a=hwi:784:1:2000
    a=bandwidthDetection:YES
    a=iChatEncryption:YES
    m=audio 16386 RTP/AVP 12 3 0
    a=rtcp:16387
    a=rtpmap:3 GSM/8000
    a=rtpmap:0 PCMU/8000
    a=rtpID:-1207316380
    m=video 16384 RTP/AVP 126 34
    a=rtcp:16385
    a=rtpmap:126 X-H264
    a=fmtp:34 imagesize 1 rules 30:352:288
    a=framerate:30
    a=RTCP:AUDIO 16387 VIDEO 16385
    a=pogo
    a=fmtp:126 imagesize 0 rules 30:320:240:320:240
    a=rtpID:1258096851
    ]

  • Jaxb validation is done automatically in webservices build using jax-ws

    I am using websphere 7.0 and jax-ws to build our webservices.My questiion is when the request comes to our webservices does jaxb automatically validates the
    request data against the xsd.Meaning if I have some restrictions specified in my xsd ,does jaxb validates the request against those restrictions or do I have to
    explicitly tell jaxb to do it via coding.
    Thanks
    m

    Is it possible to generate the validation code as part of WS generated code

  • Validation in JAXB

    Hi Friends,
    We get a response from a third party server in the form of XML document. We have a schema for the XML and but we are not sure the responce we get is valid againist the scehma.
    But we are planning to use JAXB for unmarshalling the response. There is a chance of geting an extra element/attibute in the response(The reponse is well formed). In this case we are getting a exception. But still we want to unmarsahll the response XML.
    Can we supress all the validations completely in JAXB while unmarshalling? We tried using unmarshaller.setValidating(false); but it is not working.
    Please help us.
    Thanks,
    Omkar

    We have a schema for the XML and
    but we are not sure the responce we get is valid
    againist the scehma.
    But we are planning to use JAXB for unmarshalling the
    response. There is a chance of geting an extra
    element/attibute in the response(The reponse is well
    formed). In this case we are getting a exception. But
    still we want to unmarsahll the response XML.The premise of JAXB is that the input document is valid against the schema. Even if you could trick JAXB into parsing the XML without validating, no Object would have been generated to store the extra attributes. So if you marshall again, you would get a different document than the input document.
    According to the javadocs, Unmarshaller.setValidating(false) is the default, and has to do with having a SAXParser validate along with the JAXB Validation.
    DOM is a better choice for parsing unknown but well-formed XML documents, IMO.
    -Scott
    http://www.swiftradius.com

  • Can't create a JAXB binding for ejb-jar.xml using xjc

    Hi all,
    I have been trying to build a JAXB binding for EJB deployment descriptors, mainly because I have to update a hand-cranked ejb-jar.xml file on the fly with some additions that have come from a code generator.
    I have tried to use
    xjc ejb-jar_2_1.xsd j2ee_1_4.xsd ejb-jar_2_1.xsd
    xjc on the schema definitions I found at http://java.sun.com/xml/ns/j2ee/ but I can't get it to work. It produces reams of errors, see below for a short extract.
    Of course, someone could put me out of my misery and tell me where to find a binding that someone else has done. I can't be the first chimp on the planet that has wanted to do this!
    Any help much appreciated.
    errors:
    [WARNING] warning: "blockDefault" attribute of <schema> is not supported
    line 3 of xml.xsd
    [WARNING] warning: "finalDefault" attribute of <schema> is not supported
    line 3 of xml.xsd
    [WARNING] warning: <key> identity constraint will be ignored by JAXB validation
    line 117 of j2ee_web_services_client_1_1.xsd
    [WARNING] warning: <key> identity constraint will be ignored by JAXB validation
    line 115 of ejb-jar_2_1.xsd
    [WARNING] warning: <keyref> identity constraint will be ignored by JAXB validation
    line 129 of ejb-jar_2_1.xsd
    [WARNING] warning: <key> identity constraint will be ignored by JAXB validation
    line 145 of ejb-jar_2_1.xsd
    [WARNING] warning: <keyref> identity constraint will be ignored by JAXB validation
    line 159 of ejb-jar_2_1.xsd

    Exception initializing 'oracle.dbtools.raptor.MonitorJDBCAddin' in extension 'Oracle SQL Developer': oracle.classloader.
    util.AnnotatedNoClassDefFoundError:
    Missing class: oracle.jdbc.OracleDriverThe Oracle driver is not on the classpath.

  • Unexpected element - JAXB

    We have 4 huge (similar) schemas that i compiled and successfully unmarshalled one xml file with validation turned off.
    Problems that I am facing are
    1) When I turn on validation, i run in StackOverFlow exception - tried all sorts of memory settings - no luck.
    2) When i tried to unrmarshal another XML file that is conforming to 2nd schema, i am getting error messages "Unexpected element".
    XML file is well-formed and valid (validated with XML spy).
    My understanding is that JAXB wouldn't validate XML file stucture against scheme when validation is turned off. Why is JAXB validating the structure of the XML document?
    Java file:
    Main class
    MyValidationEventHandler veh = new MyValidationEventHandler();
    JAXBContext jc = JAXBContext.newInstance( "org.tgslc.advweb.xmlbinding.response:org.tgslc.advweb.xmlbinding.response.FFEL:org.tgslc.advweb.xmlbinding.response.core:org.w3._2001.xmlschema" );
    Unmarshaller u = jc.createUnmarshaller();
    u.setValidating(false);
    u.setEventHandler(veh);
    System.out.println("isValidating : " + u.isValidating());
    org.tgslc.advweb.xmlbinding.response.CommonRecordCommonline request =
    (org.tgslc.advweb.xmlbinding.response.CommonRecordCommonline)u.unmarshal( new FileInputStream( FILE_NAME ) );
    org.tgslc.advweb.xmlbinding.response.FFEL.TransmissionDataType trans = request.getTransmissionData();
    displayTransmissionDataType( trans );
    class MyValidationEventHandler implements ValidationEventHandler
    public boolean handleEvent(ValidationEvent arg0)
    System.out.println(arg0.getMessage());
    return true;
    }

    JAXB questions should be better directed to the users list of http://jaxb.dev.java.net/
    you should subscribe to the 'users' mailing list, then post a question there.
    Thank you!

  • Replacements for deprecated meathods

    currently i am upgrading my application from 8.1 to 10.3, when i try to build the application in 10.3 , it showing build was successful but with some warnings
    here are the warnings
    C:\Abc\src\web\code\com\Abc\xml\impl\runtime\DefaultJAXBContextImpl.java:16: warning: [deprecation] javax.xml.bind.Validator in javax.xml.bind has been deprecated
    [javac] import javax.xml.bind.Validator;
    [javac] ^
    [javac] C:\Abc\src\web\code\com\Abc\xml\impl\runtime\DefaultJAXBContextImpl.java:119: warning: [deprecation] javax.xml.bind.Validator in javax.xml.bind has been deprecated
    [javac] public Validator createValidator() throws JAXBException {
    [javac] ^
    [javac] C:\Abc\src\web\code\com\Abc\xml\impl\runtime\ValidatorImpl.java:15: warning: [deprecation] javax.xml.bind.Validator in javax.xml.bind has been deprecated
    [javac] import javax.xml.bind.Validator;
    [javac] ^
    [javac] C:\Abc\src\web\code\com\Abc\xml\impl\runtime\ValidatorImpl.java:38: warning: [deprecation] javax.xml.bind.Validator in javax.xml.bind has been deprecated
    [javac] public class ValidatorImpl implements Validator
    [javac] ^
    [javac] C:\Abc\src\web\code\com\Abc\xml\impl\runtime\DefaultJAXBContextImpl.java:119: warning: [deprecation] createValidator() in javax.xml.bind.JAXBContext has been deprecated
    [javac] public Validator createValidator() throws JAXBException {
    [javac] ^
    [javac] C:\Abc\src\web\code\com\Abc\xml\impl\runtime\DefaultJAXBContextImpl.java:119: warning: [deprecation] createValidator() in javax.xml.bind.JAXBContext has been deprecated
    [javac] public Validator createValidator() throws JAXBException {
    [javac] ^
    [javac] C:\Abc\src\web\code\com\Abc\xml\impl\runtime\SAXMarshaller.java:353: warning: [deprecation] ERR_NOT_IDENTIFIABLE in com.sun.xml.bind.marshaller.Messages has been deprecated
    [javac] Messages.format(Messages.ERR_NOT_IDENTIFIABLE),
    [javac] ^
    [javac] C:\Abc\src\web\code\com\Abc\xml\impl\runtime\SAXMarshaller.java:367: warning: [deprecation] ERR_DANGLING_IDREF in com.sun.xml.bind.marshaller.Messages has been deprecated
    is there any alternative meathods for these.
    Edited by: user9138438 on Feb 23, 2010 7:22 AM

    I replied to your other related question, referring you to the JAXBContext javadoc. Here is the link again: [http://java.sun.com/javase/6/docs/api/javax/xml/bind/JAXBContext.html] . The functionality that replaces JAXB validation is provided by the Unmarshaller class.

  • Problem validating xml file - jaxb

    hi people, I'm working with jaxb to generate Java source classes from the .xsd schemas that I have. I work with 17 schemas that, a priori, I can't modify. In those schemas there are a lot of types and structures that I can use when creating an .xml file. I've read other threads with the problem of namespaces but as a solution they provide a modification on the schemas. The generation of java source is ok, I've done custoization classes and no problem, but when I try to unmarshal an input xml file I get an error of validation:
    DefaultValidationEventHandler: [ERROR]: Probably namespace URI of tag "XFFile" is wrong (correct one is "http://ww........
    A possible xml file is :
    <?xml version="1.0" encoding="UTF-8" standalone="no" ?><!DOCTYPE XFFile><XFFile xmlns:rp210Elements="http://www.smpte-ra.org/schemes/434/200X/multiplex/S377M/2004" xmlns:s377mGroups="http://www.smpte-ra.org/schemes/434/200X/groups/S377M/2004" xmlns:s377mMux="http://www.smpte-ra.org/schemes/434/200X/multiplex/S377M/2004" xmlns:s377mTypes="http://www.smpte-ra.org/schemes/434/200X/types/S377M/2004" xmlns:s380mGroups="http://www.smpte-ra.org/schemes/434/200X/groups/S380M/2004" xmlns:s381mGroups="http://www.smpte-ra.org/schemes/434/200X/groups/S381M/200X" xmlns:s382mGroups="http://www.smpte-ra.org/schemes/434/200X/groups/S382M/200X" xmlns:s385mGroups="http://www.smpte-ra.org/schemes/434/200X/groups/S385M/2004" xmlns:s422mGroups="http://www.smpte-ra.org/schemes/434/200X/groups/S422M/200X" xmlns:s422mTypes="http://www.smpte-ra.org/schemes/434/200X/types/S422M/200X" xmlns:s423mGroups="http://www.smpte-ra.org/schemes/434/200X/groups/S423M/200X">
         <s380mGroups:ClipFramework rp210Elements:InstanceID="a6.67.7a.47.19.2f.4b.10.8f.ee.1e.59.6d.4c.f1.70" rp210Elements:LinkedGenerationID="0e.10.a8.9c.96.1c.4c.11.b1.fb.0a.a9.40.22.a4.e2">
              <rp210Elements:ClipCreationDateTime>
                   <rp210Elements:Year>2006</rp210Elements:Year>
                   <rp210Elements:Month>4</rp210Elements:Month>
                   <rp210Elements:Day>18</rp210Elements:Day>
                   <rp210Elements:Hour>12</rp210Elements:Hour>
                   <rp210Elements:Minute>0</rp210Elements:Minute>
                   <rp210Elements:Second>0</rp210Elements:Second>
                   <rp210Elements:mSec4>0</rp210Elements:mSec4></rp210Elements:ClipCreationDateTime>
              <rp210Elements:FrameworkExtendedTextLanguageCode>fr</rp210Elements:FrameworkExtendedTextLanguageCode>
         </s380mGroups:ClipFramework>
    </XFFile>
    I think it's ok because someone has provided it to my company but I can't validate it because it takes elements from many schemas (am I wrong and I can?)
    i can't post the schemas because of the copyrights (damn it). I'm not asking for a solution but if someone has an idea or has had a similar problema.. I'll appreciate all comments, thanks
    Jordi
    Message was edited by:
    WuWei

    In the schema root element xs:schema add namespace declaration.
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    In the XML document root element add xmlns:xsi and xsi:noNamespaceSchemaLocation attributes.
    <root_element xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file://c:/testing.xsd">

  • JAXB 2.0 validation when marshalling

    Hi,
    I'm using JAXB to marshall and unmarshall files. The issue i'm trying to address is that when a file is being marshalled - if a value is mandatory in the schema and if the user provides null value or something then shoulding this be a validation error? I dont get any notification even if I have attached a validationhandler to my marshaller and the file is created with that particular value blank.... so anyone has any idea of how we can validate the documents created by JAXB that they're valid.
    thanks
    SA

    Ok i figured out one way of doing this by using some classes from JAXP...
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema s = null;
    try{
        s = sf.newSchema(new File("Sources/schema/test.xsd"));                    
    }catch(Exception e){
        System.err.println("Exception e: " + e.getMessage());
    marshaller.setSchema(s);
    //MyValidationHandler class implements the ValidationEventHandler interface
    MyValidationHandler gv = new MyValidationHandler();
    marshaller.setEventHandler(gv);If anyone has something to add let me know!!

  • JAXB XML Unmarshalling validation problem

    Hello,
    I'm using toplink JAXB to map XML document to an object hierarchy. The set of objects was built using Toplink workbench from the corresponding XSD file. The XSD file is specified in <toplink:resource> element using an absolute path. If I use unmarshaller validation (Unmarshaller u = jc.createUnmarshaller(); u.setValidating(true)) it works fine in embedded oc4j, but fails withan UnmarshalException "An internal error condition occurred" for Line N 1.
    It looks like the cause of the exception is that toplink cannot find the XSD file. I've tried to put the XSD file into META-INF and into classes directly, and specify the relative path, but it has failed event locally in the embedded oc4j.
    Everything works if I do not turn the validation on.
    Has anybody gotten the same issue? What could be a solution if we have to perform the validation?
    Thanks
    Kate

    Hello Kate,
    One possible work around would be use the TopLink OXM specific APIs for this unmarshal. For the most part they mirror the JAXB APIs so there usage is pretty straight forward.
    XMLContext xmlContext = new XMLContext(YOUR_JAXB_CONTEXT_PATH);
    xmlUnmarshaller = xmlContext.createUnmarshaller();One API that we offer that is not part of the standard JAXB Unmarshaller is the ability to specify an EntityResolver. This class allows you to override where the XML Schema is loaded from.
    EntityResolver entityResolver = new YourEntityResolver();
    xmlUmarshaller.setEntityResolver(entityResolver);YourEntityResolver must implement org.xml.sax.EntityResolver. There is one method on this interface that returns an InputSource representing the XML Schema. You can implement this method to load the Schema from a ClassLoader.
    -Blaise

Maybe you are looking for

  • Asset Management in Air App

    Hello All, I'm building an AIR application (2d platformer adventure game) which will be packaged on a CD for installation. I've embed the majority of the game assets into a static file to keep it simple and organized. This way I can reuse assets and

  • TS1702 Any body know what is happening with this app "eTodo" ? is no more in the iTunes store !

    Any body know what is happening with this app "eTodo" ? is no more in the iTunes store ! I have this problem for one year I think and no one can't solve that,I made 6 screen shots and I will uploading in a few seconds all of them and please just chec

  • Creating New Folders In BT Cloud

    Can someone tell me how I create new Folders in BT Cloud?  I did do a search and there were a number of postings re creating Folders for specific purposes, but  none that answered my query, I could not find anything on the creation of Folders ' in ge

  • Classic and a 03 iMac

    I My 17 G4 1GHz 2003 iMac Refuses to install or boot any version of OS9 or 10.0-10.2. It will boot fine into Panther to Leopard10.5.8. Is this a firmware issue or is it incapable of booting into classic. I have done some looking and apparently this m

  • Distribution to Church Members?

    My church sends its newsletter both by snail mail and in PDF. To save postage and trees we'd like to increase the use of PDF. Some members, though, might not have the Reader, and for those with a telephone internet connection, 33MB is prohibitive. So