Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- File file = new File("C:\DocuApi\imageDemoApp\src\main\resources\static\feed_shopy.xml");
- JAXBContext jaxbContext;
- try {
- jaxbContext = JAXBContext.newInstance("com.stack.image.dto");
- Unmarshaller jaxbUnMarshaller = jaxbContext.createUnmarshaller();
- System.out.println("Parsed XML successfully");
- List<String> imageList = new ArrayList<String>();
- List<String> nonImageList = new ArrayList<String>();
- SHOP shop = (SHOP)jaxbUnMarshaller.unmarshal(file);
- List<SHOPITEM> shopItems = shop.getSHOPITEM();
- for(SHOPITEM shopItem: shopItems){
- IMAGES images = shopItem.getIMAGES();
- List<String> imageURIs = images.getIMAGE();
- for(String imguri: imageURIs){
- Image image;
- try {
- image = ImageIO.read(new URL(imguri));
- if(image != null){
- imageList.add(imguri);
- }else{
- nonImageList.add(imguri);
- }
- } catch (MalformedURLException e) {
- nonImageList.add(imguri);
- e.printStackTrace();
- } catch (IOException e) {
- nonImageList.add(imguri);
- e.printStackTrace();
- }
- }
- }
- System.out.println("Size of imageList is- " + imageList.size());
- System.out.println("Size of nonImageList is- " + nonImageList.size());
- for(String imageUrl: nonImageList){
- System.out.println("NonImage URL " + imageUrl);
- }
- } catch (JAXBException e) {
- e.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment