6
I have a problem that I can not store more than one element in the same TAG, look at XML:
<ItemCardapio>
<nCdItemCardapio>10</nCdItemCardapio>
<nQtdeItemCardapio>2</nQtdeItemCardapio>
<ObsProducao>
<sDsObservacaoProducao>Com Gelo</sDsObservacaoProducao>
</ObsProducao>
<ObsProducao>
<sDsObservacaoProducao>Sem Açucar</sDsObservacaoProducao>
</ObsProducao>
</ItemCardapio>
As you can see, the "Obsproducao" TAG repeats instead of being like this:
<ItemCardapio>
<nCdItemCardapio>10</nCdItemCardapio>
<nQtdeItemCardapio>2</nQtdeItemCardapio>
<ObsProducao>
<sDsObservacaoProducao>Com Gelo</sDsObservacaoProducao>
<sDsObservacaoProducao>Sem Açucar</sDsObservacaoProducao>
</ObsProducao>
</itemcardapio>
Follow the class with JAXB annotations:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"nCdItemCardapio",
"nQtdeItemCardapio",
"obsProducao"
})
public static class ItemCardapio {
protected int nCdItemCardapio;
protected int nQtdeItemCardapio;
@XmlElement(name = "ObsProducao")
protected List<WsTSPaymentParamPedido.ItemCardapio.ObsProducao> obsProducao;
..........
Now the class that repeats:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"sDsObservacaoProducao"
})
public static class ObsProducao {
protected String sDsObservacaoProducao;
......
Anthony worked perfectly :) ... but how would the XSD of this XML file look, because the way I created the XSD, when the classes from it the result of the XML is the one with the tag repeating, take a look at my xsd, please:
– diegosoaresub
<xsd:element name="Itemcardapio" minOccurs="1" maxOccurs="unbounded" > <xsd:complexType> <xsd:Quence> <xsd:element name="nCdItemCardapio" type="xsd:int" /> <xsd:element name="nQtdeItemCardapio" type="xsd:int" /> <xsd:element name="Obsproducao" minOccurs="0" maxOccurs="unbounded" > <xsd:complexType> <xsd:Sequence> <xsd:element name="sDsObservedProduction" type="xsd:string" minOccurs="0" /> </xsd:Sequence> </xsd:complexType> </xsd:element> </xsd:Sequence> </xsd:complexType> </xsd:element>
– diegosoaresub
You can use the scheming to generate an xsd of your class and see how Java does this construction. Anyway, if I was going to generate an XSD in hand (overall I avoid that) I would use a
xsd:complexType
to the list (containing a string sequenceunbouded
whose name issDsObservacaoProducao
). TheItemCardapio
would have axsd:element
calledObsProducao
referencing this complex type.– Anthony Accioly
Did it work Diego? If yes please accept the answer.
– Anthony Accioly
Gave yes, thanks friend :)
– diegosoaresub