Re: Strange binding behaviour
Jacob Danner <[email protected]> Wed, 13 Jul 2011 07:55:43 -0700
| Newsgroups | gmane.text.xml.xmlbeans.user |
|---|---|
| Message-ID | <CAM8xMGsbX38LqcbayfKQKSa5AcRZqgVRU_cWvcW_zNpbxKcL_g@mail.gmail.com> |
Have you tried validating the instance. The easiest way to do so might be to add a call to xmlDoc.validate(xmloptions) after having set the error listener. Can you let us know what the outcome of validation is? Thanks, -jacobd On Jul 13, 2011 6:11 AM, "Henrique" <[email protected]> wrote: > Hi everybody! > > I need to bind a XML doc like this: > > <?xml version="1.0" encoding="UTF-8"?> > <mapping> > <em> > <tag>PEOPLE</tag> > <tag>INDIVIDUAL</tag> > <base_ns>http://www.semanticweb.org/ontologies/2011/1/Familia.owl# > </base_ns> > <local_name>Pessoa</local_name> > </em> > <em> > <tag>PEOPLE</tag> > <tag>COLLECTIVE</tag> > <base_ns>http://www.semanticweb.org/ontologies/2011/1/Familia.owl# > </base_ns> > <local_name>Familia</local_name> > </em> > </mapping> > > <em> can repeat unbound, the same with <tag>. > And I have this schema: > > <?xml version="1.0" encoding="UTF-8"?> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" > elementFormDefault="qualified"> > <xs:element name="mapping"> > <xs:complexType> > <xs:sequence> > <xs:element maxOccurs="unbounded" ref="em"/> > </xs:sequence> > </xs:complexType> > </xs:element> > > <xs:element name="em"> > <xs:complexType> > <xs:sequence> > <xs:element maxOccurs="unbounded" ref="tag"/> > <xs:element ref="base_ns"/> > <xs:element ref="local_name"/> > </xs:sequence> > </xs:complexType> > </xs:element> > > <xs:element name="tag" type="xs:NCName"/> > <xs:element name="base_ns" type="xs:anyURI"/> > <xs:element name="local_name" type="xs:NCName"/> > </xs:schema> > > Now, XMLBeans generates the right Java classes as far as I can see. The > problem is this: > > //assume mapFilePath point to xml file above > MappingDocument xmlDoc = MappingDocument.Factory.parse(new > File(mapFilePath)); > > for(EmDocument.Em em : xmlDoc.getMapping().getEmList()) { > > //This always prints: 1 > System.out.println(em.getTagList().size()); > > } > > So, basically, no matter how many <tag> elements I have on the XML, somehow > XMLBeans only gets one! But it works fine with <em> elements... > I've tried to group <tag> inside a <tags> element: > <tags> > <tag>PEOPLE</tag> > <tag>INDIVIDUAL</tag> > </tags> > > with corresponding schema changes, but it strangely displays the exact same > behaviour. It only gets one <tag>... As a matter of fact, in this last case, > if I do em.getTags() I get null! > > If someone could shed some light on this I'd be most grateful! > > Cheers, > Henrique Nunes