|
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----- minOccurs, maxOccurs are members of XSParticle. Hello, 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. -- Maksym Kovalenko |
Title:
- Getting MaxOcurrs/MinOcurrs Rubens Del Monte
- Re: Getting MaxOcurrs/MinOcurrs Maksym Kovalenko
- RES: Getting MaxOcurrs/MinOcurrs Rubens Del Monte
- Re: RES: Getting MaxOcurrs/MinOcurrs Maksym Kovalenko
