Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

probleme avec attributs XML complex et JOX

2 réponses
Avatar
pcouas
Bonjour,

J'utilise JOX 1.16 pour transformer des chaines en objets JavaBeans,
pour les fichiers XML simple c'est ok, mais j'ai desormais des fichiers
avec des attriuts complexe du style.
J'ai l'impression que cela n'est pas possible, je n'ai que des erreurs

Merci d'avance
Philippe

<MarkTest foo=3D'8' bar=3D\"AAAAAAThis is the bar value\">
<thingies>Moe</thingies> <thingies>Larry</thingies>
<sub age=3D\"35\" name=3D\"Mark\" />
<cell id=3D'1' tdata=3D'0' style=3D 'valeur' langdata=3D'fr' color=3D'green'
>AAA</cell>
<cell id=3D'2' tdata=3D'0' style=3D'valeur' langdata=3D'fr' color=3D'green'
>BBB</cell>
</MarkTest>


<table>
<row tdata=3D'0'><cell chp=3D'0'>Quantit=E9</cell><cell
chp=3D'1'>Prix%20unitaire</cell><cell chp=3D'2'>Total</cell></row>
<row tdata=3D'2'><cell chp=3D'0'>5</cell><cell
chp=3D'1'>10.00</cell><cell chp=3D'2'>50.00</cell></row>
</table>

2 réponses

Avatar
pcouas
Un exemple simple avec le message d'erreur

String x2=new String("<MarkTest foo='8' bar="AAAAAAThis is

the bar value"><thingies>Moe</thingies> <thingies>Larry</thingies><sub

age="35" name="Mark"> </sub> </MarkTest>");
TestBean2 testBean2 (TestBean2)BeanXMLMapping.fromXML(x2,TestBean2.class);
System.out.println("TEST2");
System.out.println("foo "+testBean2.getFoo());
System.out.println("bar "+testBean2.getBar());


import util.xml.jox.*;
import java.util.*;


public class TestBean2 implements java.io.Serializable
{
protected int foo;
protected String bar;
protected Vector thingies;
protected Vector subbean;


public TestBean2()
{
bar = "";
//baz = new Date();
thingies = new Vector();
}


public int getFoo() { return foo; }
public void setFoo(int aFoo) { foo = aFoo; }


public String getBar() { return bar; }
public void setBar(String aBar) { bar = aBar; }


public TestSubbean []getSub() {


TestSubbean[] tretThingies = new TestSubbean[subbean.size()];
if (subbean.size() > 0) subbean.copyInto(tretThingies);
return tretThingies;
}


public void setSub(TestSubbean[] aSub) {
thingies = new Vector(aSub.length);
for (int i=0; i < aSub.length; i++)
{
subbean.addElement(aSub[i]);
}
}


public String[] getThingies()
{
String[] retThingies = new String[thingies.size()];
if (thingies.size() > 0) thingies.copyInto(retThingies);


return retThingies;
}


public void setThingies(String[] newThingies)
{
thingies = new Vector(newThingies.length);
for (int i=0; i < newThingies.length; i++)
{
thingies.addElement(newThingies[i]);
}
}


public String getThingies(int i)
{
return (String) thingies.elementAt(i);
}


public void setThingies(int i, String thingy)
{
thingies.setElementAt(thingy, i);
}



}


java.io.IOException: Error parsing XML document:
java.lang.reflect.InvocationTargetException
at
util.xml.jox.JOXSAXBeanInput.readObject(JOXSAXBeanInput.java:166)
at
util.xml.jox.JOXBeanInputStream.readObject(JOXBeanInputStream.java:96)
at util.xml.jox.BeanXMLMapping.fromXML(BeanXMLMapping.java:34)
at TestAttrDeser.main(TestAttrDeser.java:46)


Merci d'avance
Philippe
Avatar
pcouas