You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Rubens Del Monte <ru...@soluzionautilities.com.br> on 2003/10/13 20:44:04 UTC

Getting MaxOcurrs/MinOcurrs

Hello,

I´m trying to know if a node has a Max/Min Ocurrs indicator but I don´t find
a way, Does anyone know how to do it ?
I´m using "org.apache.xerces.dom.PSVIDocumentImpl", so I have the
declarations, I can get the facets, but I can´t find out if a node has a
max/minocurrs atribbutte. If anyone knows, please help me.

Thanks,

Rubens

Re: RES: Getting MaxOcurrs/MinOcurrs

Posted by Maksym Kovalenko <mk...@marketswitch.com>.
This is because particle for a complex type is model group, sequence in 
your case. Naturally, it has 1 min and max occurences.
You need to get sequnce subparticle, whose term references to your 
element declaration. :)

Max

Rubens Del Monte wrote:

> Max,
>
>  
>
>   I tried using Xsparticle, but I´ve must been doing something wrong, 
> cause I always get max = 1, min = 1 and maxunbounded = false. My code, 
> xml and schema are bellow, please take a look. Another doubt that I 
> have is that it´s possible to define maxOccurs to simpletype elements, 
> but you can only retrive XSparticle within XSComplexTypeDefinition 
>
>  
>
> Thanks,
>
>  
>
> Rubens
>
>  
>
> Here´s the code :
>
>  
>
> public XMLtest() {       
>
>         try
>
>         {
>
>             DOMParser parser = new DOMParser();
>
>             
> parser.setFeature("http://xml.org/sax/features/validation",true);
>
>             
> parser.setFeature("http://apache.org/xml/features/validation/schema",true);
>
>              
> parser.setProperty("http://apache.org/xml/properties/dom/document-class-name",
>
>                     "org.apache.xerces.dom.PSVIDocumentImpl");
>
>             parser.parse("C:/SGS/test/test.xml");
>
>             doc = parser.getDocument();           
>
>         }
>
>          catch (SAXException sxe)
>
>         {
>
>            // Error generated by this application
>
>            // (or a parser-initialization error)
>
>            Exception  x = sxe;
>
>            if (sxe.getException() != null)
>
>                x = sxe.getException();
>
>            x.printStackTrace();
>
>         }
>
>         catch (IOException ioe)
>
>         {
>
>            // I/O error
>
>            ioe.printStackTrace();
>
>         }
>
>         
>
>         //buildForm(doc.getDocumentElement());       
>
>         check(doc.getDocumentElement());
>
>     }
>
>    
>
>     private void check(Node node) {
>
>         XSTypeDefinition psvi = ((PSVIElementNSImpl) 
> node).getElementDeclaration().getTypeDefinition();        
>
>        
>
>         if (psvi.getTypeCategory() == 
> XSTypeDefinition.COMPLEX_TYPE)           
>
>         {
>
>             XSComplexTypeDecl c = (XSComplexTypeDecl) psvi;
>
>             System.out.println("Node Name : "+node.getNodeName());
>
>             XSParticle p = c.getParticle();
>
>             System.out.println("Max : "+p.getMaxOccurs());
>
>             System.out.println("Min : "+p.getMinOccurs());
>
>             System.out.println("Maxu: 
> "+p.getMaxOccursUnbounded());                                    
>
>         }       
>
>         Node son = node.getFirstChild();
>
>            
>
>             while (son != null)
>
>             {
>
>                 if (son.getNodeType() == Node.ELEMENT_NODE)
>
>                     check(son);
>
>                 son = son.getNextSibling();           
>
>             }                    
>
>     }
>
>  
>
> here´s the output :
>
>  
>
> Node Name : test
>
> Max : 1
>
> Min : 1
>
> Maxu: false
>
> Node Name : testc
>
> Max : 1
>
> Min : 1
>
> Maxu: false
>
> Node Name : testc
>
> Max : 1
>
> Min : 1
>
> Maxu: false
>
>  
>
> Here´s the XML and Schema :
>
>  
>
> <?xml version="1.0" encoding="UTF-8"?>
>
>  
>
> <test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
> xsi:noNamespaceSchemaLocation="test.xsd">
>
>   <name>Rubens Cardoso Del Monte</name>
>
>   <name>Rubens Cardoso Del Monte</name>
>
>   <testc>
>
>     <name2>Rubens Cardoso Del Monte</name2>
>
>     <adress>Rubens Cardoso Del Monte</adress> 
>
>   </testc>   
>
>   <testc>
>
>     <name2>Rubens Cardoso Del Monte</name2>
>
>     <adress>Rubens Cardoso Del Monte</adress> 
>
>   </testc> 
>
> </test>
>
>  
>
> <?xml version="1.0" encoding="UTF-8"?>
>
>  
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>
>  <xs:element name="test">
>
>   <xs:complexType>
>
>   <xs:sequence>
>
>    <xs:element name="name" maxOccurs="2">
>
>     <xs:simpleType>
>
>      <xs:restriction base="xs:string">
>
>       <xs:maxLength value="100"/>
>
>      </xs:restriction>
>
>     </xs:simpleType>
>
>    </xs:element> 
>
>    <xs:element name="testc" maxOccurs="2">
>
>     <xs:complexType>
>
>     <xs:sequence>   
>
>      <xs:element name="name2">
>
>       <xs:simpleType>
>
>        <xs:restriction base="xs:string">
>
>         <xs:maxLength value="100"/>
>
>        </xs:restriction>
>
>       </xs:simpleType>
>
>      </xs:element>
>
>      <xs:element name="adress">
>
>       <xs:simpleType>
>
>        <xs:restriction base="xs:string">
>
>         <xs:maxLength value="100"/>
>
>        </xs:restriction>
>
>       </xs:simpleType>
>
>      </xs:element>
>
>     </xs:sequence>
>
>     </xs:complexType>   
>
>    </xs:element>  
>
>   </xs:sequence> 
>
>   </xs:complexType>  
>
>  </xs:element>            
>
> </xs:schema>
>
>  
>
>  
>
> -----Mensagem original-----
> De: Maksym Kovalenko [mailto:mkovalenko@marketswitch.com]
> Enviada em: segunda-feira, 13 de outubro de 2003 15:56
> Para: xerces-j-user@xml.apache.org
> Assunto: Re: Getting MaxOcurrs/MinOcurrs
>
>  
>
> minOccurs, maxOccurs are members of XSParticle.
> When you traverse XSModelGroup you get the list of particles 
> (XSParticle). Particle's term may reference to element declaration, if 
> this is declaration of your element of interest use 
> XSParticle.getMinOccurs(), XSParticle.getMinOccursUnbounded(), 
> XSParticle.getMaxOccurs(), XSParticle.getMaxOccursUnbounded() to get 
> min/max occurences of element.
>
> Max
>
> Rubens Del Monte wrote:
>
> Hello,
>
> I´m trying to know if a node has a Max/Min Ocurrs indicator but I 
> don´t find a way, Does anyone know how to do it ?
>
> I´m using "org.apache.xerces.dom.PSVIDocumentImpl", so I have the 
> declarations, I can get the facets, but I can´t find out if a node has 
> a max/minocurrs atribbutte. If anyone knows, please help me.
>
> Thanks,
>
> Rubens
>
>  
>
> -- 
>
> ------------------------------------------------------------------------
>
> Maksym Kovalenko
> Software Engineer
> Marketswitch Corporation
> http://www.marketswitch.com <http://www.marketswitch.com/>
> 108 Powers Court, Suite 225
> Dulles, VA 20166
> Phone: +1 (703) 444-6750 ext. 302
> Fax: +1 (703) 444-6812
>

-- 
------------------------------------------------------------------------

Maksym Kovalenko
Software Engineer
Marketswitch Corporation
http://www.marketswitch.com <http://www.marketswitch.com/>
108 Powers Court, Suite 225
Dulles, VA 20166
Phone: +1 (703) 444-6750 ext. 302
Fax: +1 (703) 444-6812


RES: Getting MaxOcurrs/MinOcurrs

Posted by Rubens Del Monte <ru...@soluzionautilities.com.br>.
Max,

  I tried using Xsparticle, but I´ve must been doing something wrong, cause
I always get max = 1, min = 1 and maxunbounded = false. My code, xml and
schema are bellow, please take a look. Another doubt that I have is that
it´s possible to define maxOccurs to simpletype elements, but you can only
retrive XSparticle within XSComplexTypeDefinition

Thanks,

Rubens

Here´s the code :

public XMLtest() {
        try
        {
            DOMParser parser = new DOMParser();

parser.setFeature("http://xml.org/sax/features/validation",true);

parser.setFeature("http://apache.org/xml/features/validation/schema",true);

parser.setProperty("http://apache.org/xml/properties/dom/document-class-name
",
                    "org.apache.xerces.dom.PSVIDocumentImpl");
            parser.parse("C:/SGS/test/test.xml");
            doc = parser.getDocument();
        }
         catch (SAXException sxe)
        {
           // Error generated by this application
           // (or a parser-initialization error)
           Exception  x = sxe;
           if (sxe.getException() != null)
               x = sxe.getException();
           x.printStackTrace();
        }
        catch (IOException ioe)
        {
           // I/O error
           ioe.printStackTrace();
        }

        //buildForm(doc.getDocumentElement());
        check(doc.getDocumentElement());
    }

    private void check(Node node) {
        XSTypeDefinition psvi = ((PSVIElementNSImpl)
node).getElementDeclaration().getTypeDefinition();

        if (psvi.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE)
        {
            XSComplexTypeDecl c = (XSComplexTypeDecl) psvi;
            System.out.println("Node Name : "+node.getNodeName());
            XSParticle p = c.getParticle();
            System.out.println("Max : "+p.getMaxOccurs());
            System.out.println("Min : "+p.getMinOccurs());
            System.out.println("Maxu: "+p.getMaxOccursUnbounded());
        }
        Node son = node.getFirstChild();

            while (son != null)
            {
                if (son.getNodeType() == Node.ELEMENT_NODE)
                    check(son);
                son = son.getNextSibling();
            }
    }

here´s the output :

Node Name : test
Max : 1
Min : 1
Maxu: false
Node Name : testc
Max : 1
Min : 1
Maxu: false
Node Name : testc
Max : 1
Min : 1
Maxu: false

Here´s the XML and Schema :

<?xml version="1.0" encoding="UTF-8"?>

<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
  <name>Rubens Cardoso Del Monte</name>
  <name>Rubens Cardoso Del Monte</name>
  <testc>
    <name2>Rubens Cardoso Del Monte</name2>
    <adress>Rubens Cardoso Del Monte</adress>
  </testc>
  <testc>
    <name2>Rubens Cardoso Del Monte</name2>
    <adress>Rubens Cardoso Del Monte</adress>
  </testc>
</test>

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xs:element name="test">
  <xs:complexType>
  <xs:sequence>
   <xs:element name="name" maxOccurs="2">
    <xs:simpleType>
     <xs:restriction base="xs:string">
      <xs:maxLength value="100"/>
     </xs:restriction>
    </xs:simpleType>
   </xs:element>
   <xs:element name="testc" maxOccurs="2">
    <xs:complexType>
    <xs:sequence>
     <xs:element name="name2">
      <xs:simpleType>
       <xs:restriction base="xs:string">
        <xs:maxLength value="100"/>
       </xs:restriction>
      </xs:simpleType>
     </xs:element>
     <xs:element name="adress">
      <xs:simpleType>
       <xs:restriction base="xs:string">
        <xs:maxLength value="100"/>
       </xs:restriction>
      </xs:simpleType>
     </xs:element>
    </xs:sequence>
    </xs:complexType>
   </xs:element>
  </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>


-----Mensagem original-----
De: Maksym Kovalenko [mailto:mkovalenko@marketswitch.com]
Enviada em: segunda-feira, 13 de outubro de 2003 15:56
Para: xerces-j-user@xml.apache.org
Assunto: Re: Getting MaxOcurrs/MinOcurrs

minOccurs, maxOccurs are members of XSParticle.
When you traverse XSModelGroup you get the list of particles (XSParticle).
Particle's term may reference to element declaration, if this is declaration
of your element of interest use XSParticle.getMinOccurs(),
XSParticle.getMinOccursUnbounded(), XSParticle.getMaxOccurs(),
XSParticle.getMaxOccursUnbounded() to get min/max occurences of element.

Max

Rubens Del Monte wrote:


Hello,
I´m trying to know if a node has a Max/Min Ocurrs indicator but I don´t find
a way, Does anyone know how to do it ?
I´m using "org.apache.xerces.dom.PSVIDocumentImpl", so I have the
declarations, I can get the facets, but I can´t find out if a node has a
max/minocurrs atribbutte. If anyone knows, please help me.
Thanks,
Rubens

--


  _____

Maksym Kovalenko
Software Engineer
Marketswitch Corporation
http://www.marketswitch.com <http://www.marketswitch.com/>
108 Powers Court, Suite 225
Dulles, VA 20166
Phone: +1 (703) 444-6750 ext. 302
Fax: +1 (703) 444-6812

Re: Getting MaxOcurrs/MinOcurrs

Posted by Maksym Kovalenko <mk...@marketswitch.com>.
minOccurs, maxOccurs are members of XSParticle.
When you traverse XSModelGroup you get the list of particles 
(XSParticle). Particle's term may reference to element declaration, if 
this is declaration of your element of interest use 
XSParticle.getMinOccurs(), XSParticle.getMinOccursUnbounded(), 
XSParticle.getMaxOccurs(), XSParticle.getMaxOccursUnbounded() to get 
min/max occurences of element.

Max

Rubens Del Monte wrote:

> Hello,
>
>  
>
> I´m trying to know if a node has a Max/Min Ocurrs indicator but I 
> don´t find a way, Does anyone know how to do it ?
>
> I´m using "org.apache.xerces.dom.PSVIDocumentImpl", so I have the 
> declarations, I can get the facets, but I can´t find out if a node has 
> a max/minocurrs atribbutte. If anyone knows, please help me.
>
>  
>
> Thanks,
>
>  
>
> Rubens
>

-- 
------------------------------------------------------------------------

Maksym Kovalenko
Software Engineer
Marketswitch Corporation
http://www.marketswitch.com <http://www.marketswitch.com/>
108 Powers Court, Suite 225
Dulles, VA 20166
Phone: +1 (703) 444-6750 ext. 302
Fax: +1 (703) 444-6812