Nicely done, Mocky! Though I think with the current CVS code you'd need
to specify item-type="java.lang.String" on the collection, or
type="java.lang.String" on the <structure> element within the
collection, or the <value> element within that. You might want to try
running this with a CVS build to see what error you get. There were some
cases before where JiBX would default to String within a collection, but
it was inconsistent with the documentation.
- Dennis
Mocky Habeeb wrote:
I was able to do it by using a <structure name=""> to bring all of
<XPTO>'s attributes and elements down to the level of class A. Then I
used a <structure field=""> to push just <XPTO>'s attributes into the
XPTO object. And finally a <collection field=""> to treat what was
left in <XPTO> as a collection. This is the binding I used:
<binding direction="both" value-style="element" >
<mapping name="A" class="A" >
<structure name="XPTO">
<structure field="XPTO" type="XPTO">
<value name="A" field="a"
style="attribute"/>
<value name="B" field="b"
style="attribute"/>
</structure>
<collection field="arr">
<structure name="ITER" type="Iter">
<value name="id" field="id"
style="attribute"/>
</structure>
</collection>
</structure>
</mapping>
</binding>
With the following code and data:
public class A {
public ArrayList arr;
public Object XPTO;
public static void main(String[] argz) {
IBindingFactory bfact = null;
IUnmarshallingContext uctx = null;
Object result = null;
try {
bfact = BindingDirectory.getFactory(A.class);
uctx = bfact.createUnmarshallingContext();
result = uctx.unmarshalDocument(new
FileInputStream("data.xml"), null);
System.out.println(result);
} catch (Exception e) { e.printStackTrace();}
}
public String toString() {
return "Instance of class A {\n\t" + XPTO.toString() + "\n\t"
+ arr.toString() + "\n}";
}
}
public class Iter {
private String id;
public String toString() {
return "Iter: " + id;
}
}
public class XPTO {
private String a;
private String b;
public String toString() {
return "XPTO(" + a + ", " + b + ")";
}
}
<A>
<XPTO A="1" B="2">
<ITER id="run"/>
<ITER id="tin"/>
<ITER id="can"/>
</XPTO>
</A>
-----Original Message-----
*From:* [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] *On Behalf Of
*Nuno Ferreira
*Sent:* Monday, September 19, 2005 7:26 AM
*To:* [email protected]
*Subject:* [jibx-users] Collection issue
Hi all,
i´ve tried to marshall a collection like this!!!
public class A {
public Arraylist arr;
public Object XPTO;
}
and the xml look like this...
<A>
<XPTO A=1 B=2>
<ITER1 .../>
<ITER2 .../>
<ITER3 .../>
</XPTO>
</A>
the XML its not very smart, but a´m stuck with it.
i want to put the ITER(n) tag into de arr Arraylist and the
propertys in the tag XPTO into de object XPTO.
any ideas???
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users