My program reads in xml data to automatically fill in the orders in the database. This program is written in Java with jpa, since it builds on sets. When 1 client, orders 1 edition, for 1 delivery adres, I can easily parse the xml. But what if we would have multiple editions or delivery adresses? As an example, I here have an example of a possible xml file, offcourse without sensitive data:
<Order>
<Id>id</Id>
<Platform>platform</Platform>
<Brand></Brand>
<Orderdate>2022-03-14T18:34:28+01:00</Orderdate>
<Items>
<Item>
<Paper>
<EditionId>editionnr</EditionId>
<Name>nameOfEdition</Name>
<Platform>platform</Platform>
<Format>
<Name>Tabloid</Name>
</Format>
<NumberOfPages>x</NumberOfPages>
<PaperKind>paperkind</PaperKind>
<File name="xxxxxx"/>
</Paper>
<Contacts>
<Contact>
<Copies>x</Copies>
<Company>companyName</Company>
<Salutation></Salutation>
<Firstname>firstname</Firstname>
<Lastname>lastname</Lastname>
<Street>street</Street>
<HouseNumber>nr<HouseNumber/>
<BoxNumber/>
<Zip>xxxx</Zip>
<City>city</City>
<Country>countrytag</Country>
<C_Email>mail</C_Email>
</Contact>
</Contacts>
</Item>
<Item>
<Paper>
<EditionId>editionnr</EditionId>
<Name>nameOfEdition</Name>
<Platform>platform</Platform>
<Format>
<Name>Tabloid</Name>
</Format>
<NumberOfPages>x</NumberOfPages>
<PaperKind>paperkind</PaperKind>
<File name="xxxxxx"/>
</Paper>
<Contacts>
<Contact>
<Copies>x</Copies>
<Company>companyName</Company>
<Salutation></Salutation>
<Firstname>firstname</Firstname>
<Lastname>lastname</Lastname>
<Street>street</Street>
<HouseNumber>nr<HouseNumber/>
<BoxNumber/>
<Zip>xxxx</Zip>
<City>city</City>
<Country>countrytag</Country>
<C_Email>mail</C_Email>
</Contact>
</Contacts>
</Item>
</Items>
</Order>
I use this line of java code to get the specified information per node (offcourse I parse the entire xml in advance), which I than insert in my New Order () as the specified attribute :
eElements.getElementsByTagName("EditionId").item(0).getTextContext();
My question is, when I have multiple items or delivery adresses, how do instruct my program to check this?
in human language I want it do this:
- check wheter there is only 1 item node or multiple
- if only one, no problem
- if multiple, create a line for each item
And offcourse the same for delivery adresses. But since their is only 1 contact per item, in this case you cannot see in the xml. In some of the xml's, they alse have multiple contacts within the item. But I guess this will be exactly the same method as for multiple items within orders.
What is the best way to instruct this?