Re: xmlsbeans 2.5 does not check sequence order ?

2011-05-04 Thread Jerry Sy


  
  
read about xmlbeans validation here
http://xmlbeans.apache.org/docs/2.0.0/guide/conValidationWithXmlBeans.html

I test using this code
    String testschema = "\n" +
      "
      " 
  targetNamespace=\"http://www.colis-logistique.com/i-net/wsapi\"\n"
  +
      " 
  xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" +
      "  elementFormDefault=\"qualified\">\n" +
      "  \n" +
      "    \n" +
      "   \n" +
      " \n" +
      " \n" +
      " \n" +
      " \n" +
      "   \n" +
      "    \n" +
      "  \n" +
      " ";
      String testxml =
  ""http://www.colis-logistique.com/i-net/wsapi\">\n"
  +
      "   
  2011-05-02T16:57:33.136Z\n"
  +
      "   
  SUCCESS\n" +
      "
  ZjY5MDdlYWI4MGQxMGQ3MjM5OTExZmVmNjQ1NjY3ZDY3NTVkYmQ5MGQ4YTViM2JlOTE1OWU3ODFjZGJlYjIxNg==\n"
  +
      " ";
  
      SchemaTypeSystem sts1 = XmlBeans.compileXsd(new
  XmlObject[]{XmlObject.Factory.parse(testschema)},
      XmlBeans.getBuiltinTypeSystem(),null);
      XmlObject x1 =
  sts1.parse(testxml,sts1.findDocumentType(new
QName("http://www.colis-logistique.com/i-net/wsapi","DeclareParcelsAndCustomsResponse")),null);
      XmlOptions xo = new XmlOptions();
      ArrayList errorlist = new
  ArrayList();
      xo.setErrorListener(errorlist);
      if (!x1.validate(xo)) {
      for (XmlValidationError e:errorlist) {
      System.out.println(e.getMessage());
      }
      }

and get this output
Expected element
'Version@http://www.colis-logistique.com/i-net/wsapi' instead of
'Timestamp@http://www.colis-logistique.com/i-net/wsapi' here in
element
DeclareParcelsAndCustomsResponse@http://www.colis-logistique.com/i-net/wsapi
Expected element
'Version@http://www.colis-logistique.com/i-net/wsapi' instead of
'AckCode@http://www.colis-logistique.com/i-net/wsapi' here in
element
DeclareParcelsAndCustomsResponse@http://www.colis-logistique.com/i-net/wsapi
Expected element
'Version@http://www.colis-logistique.com/i-net/wsapi' instead of
'HMacBase64Code@http://www.colis-logistique.com/i-net/wsapi' here in
element
DeclareParcelsAndCustomsResponse@http://www.colis-logistique.com/i-net/wsapi
Expected element
'Version@http://www.colis-logistique.com/i-net/wsapi' before the end
of the content in element
DeclareParcelsAndCustomsResponse@http://www.colis-logistique.com/i-net/wsapi

using your code, you can do ans.validate()

Jerry


On 11/11/2011 11:46 AM, philippe.legay.exte...@telintrans.fr wrote:

  
  Hello, 
  
  
  I parse a xml string, but
wmlsbeans
does not see that the version element is not present ! I am
expecting an
exception like I have one when there is a syntax error in the
xml string.
  
  
  
  So my problems with xmlsbeans 2.5
 are
:
  
  - xmlsbeans  does not throw an
exception when an element of a sequence is not here ? 
  
  - xmlsbeans  does not throw an
exception when an element of a sequence is not  at the right
position
?
  
   - xmlsbeans  does not throw
an exception when an element of a sequence is not declared in
the XSD ?
  
  
  
  My java code is :
  
  DeclareParcelsAndCustomsResponseDocument
ansDoc
= DeclareParcelsAndCustomsResponseDocument.Factory.parse(answer);
 
  
  DeclareParcelsAndCustomsResponseDocument.DeclareParcelsAndCustomsResponse
ans
= ansDoc.getDeclareParcelsAndCustomsResponse() ; 
  
  
  XSD Source 
===
  
  
  
  
  
   
targetNamespace="http://www.colis-logistique.com/i-net/wsapi"
  
   
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  
   
elementFormDefault="qualified">
  
    
  
      
  
         
  
           
  
           
  
           
  
           
  
         
  
      
  
    
  
  
  
  
  XML String
  
  =
  
  "http://www.colis-logistique.com/i-net/wsapi">
  
     
2011-05-02T16:57:33.136Z
  
     
SUCCESS
  
     
 ZjY5MDdlYWI4MGQxMGQ3MjM5OTExZmVmNjQ1NjY3ZDY3NTVkYmQ5MGQ4YTViM2JlOTE1OWU3ODFjZGJlYjIxNg==
  
  
  
   

Re: xmlsbeans 2.5 does not check sequence order ?

2011-05-04 Thread Jacob Danner
In general xmlbeans will not throw an exception for instances that are
invalid according to the schema.
If you want to throw an exception on this, try validating the instance with
an xmloptions that includes an error listener. If after checking the error
list for errors you are concerned with after validation you can throw your
own exception.
HTH,
-jacobd
On May 4, 2011 11:18 AM,  wrote:
> Hello,
>
> I parse a xml string, but wmlsbeans does not see that the version element
> is not present ! I am expecting an exception like I have one when there is

> a syntax error in the xml string.
>
> So my problems with xmlsbeans 2.5 are :
> - xmlsbeans does not throw an exception when an element of a sequence is
> not here ?
> - xmlsbeans does not throw an exception when an element of a sequence is
> not at the right position ?
> - xmlsbeans does not throw an exception when an element of a sequence is
> not declared in the XSD ?
>
> My java code is :
> DeclareParcelsAndCustomsResponseDocument ansDoc =
> DeclareParcelsAndCustomsResponseDocument.Factory.parse(answer);
> DeclareParcelsAndCustomsResponseDocument.DeclareParcelsAndCustomsResponse
> ans = ansDoc.getDeclareParcelsAndCustomsResponse() ;
>
> XSD Source
> ===
> 
>  targetNamespace="http://www.colis-logistique.com/i-net/wsapi";
> xmlns:xsd="http://www.w3.org/2001/XMLSchema";
> elementFormDefault="qualified">
> 
> 
> 
>  maxOccurs="1"/>
>  maxOccurs="1"/>
>  maxOccurs="1"/>
>  minOccurs="1" maxOccurs="1"/>
> 
> 
> 
> 
>
> XML String
> =
>  xmlns:wsap="http://www.colis-logistique.com/i-net/wsapi";>
> 2011-05-02T16:57:33.136Z
> SUCCESS
>
>
ZjY5MDdlYWI4MGQxMGQ3MjM5OTExZmVmNjQ1NjY3ZDY3NTVkYmQ5MGQ4YTViM2JlOTE1OWU3ODFjZGJlYjIxNg==
> 
>
> validate xsd .xml => OK : There is no VERSION : I agree with this.
> But, I do not have the same behavior in my own java code ?
>
> Any idea ?
>
> Thanks,
> PHL
>
> ___
> Philippe LEGAY
> TELINTRANS
> Direction Production
> Département Intégration des Projets
> E-Mail : philippe.legay.exte...@telintrans.fr
> Tel : (+33) 01 56 30 74 24
>
> P Afin de contribuer au respect de l'environnement, merci de n'imprimer ce

> courriel que si nécessaire.


xmlsbeans 2.5 does not check sequence order ?

2011-05-04 Thread philippe . legay . externe
Hello, 

I parse a xml string, but wmlsbeans does not see that the version element 
is not present ! I am expecting an exception like I have one when there is 
a syntax error in the xml string. 

So my problems with xmlsbeans 2.5  are :
- xmlsbeans  does not throw an exception when an element of a sequence is 
not here ? 
- xmlsbeans  does not throw an exception when an element of a sequence is 
not  at the right position ?
 - xmlsbeans  does not throw an exception when an element of a sequence is 
not declared in the XSD ? 

My java code is :
DeclareParcelsAndCustomsResponseDocument ansDoc = 
DeclareParcelsAndCustomsResponseDocument.Factory.parse(answer); 
DeclareParcelsAndCustomsResponseDocument.DeclareParcelsAndCustomsResponse 
ans = ansDoc.getDeclareParcelsAndCustomsResponse() ; 

XSD Source 
===

http://www.colis-logistique.com/i-net/wsapi";
  xmlns:xsd="http://www.w3.org/2001/XMLSchema";
  elementFormDefault="qualified">
  

   
 
 
 
 
   

  


XML String
=
http://www.colis-logistique.com/i-net/wsapi";>
2011-05-02T16:57:33.136Z
SUCCESS
 
ZjY5MDdlYWI4MGQxMGQ3MjM5OTExZmVmNjQ1NjY3ZDY3NTVkYmQ5MGQ4YTViM2JlOTE1OWU3ODFjZGJlYjIxNg==


 validate xsd .xml => OK : There is no VERSION : I agree with this. 
But, I do not have the same behavior in my own java code ? 

Any idea ? 

Thanks,
PHL

___
Philippe LEGAY
TELINTRANS
Direction Production
Département Intégration des Projets
E-Mail : philippe.legay.exte...@telintrans.fr
Tel : (+33) 01 56 30 74 24

P Afin de contribuer au respect de l'environnement, merci de n'imprimer ce 
courriel que si nécessaire.