Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help with simple XML reading example using StAX

795628Nov 17 2009 — edited Nov 20 2009
Please, could somebody help me with this issue?
Or, could somebody point me to a comprehensive StAX tutorial?
thanks!

I have prepared a simple sample that looks like 'homework', but this newbie task is getting me crazy...

I just want to store in the object Shop[] shopsArray; the next XML file, using StAX:
<?xml version="1.0" encoding="ISO-8859-1"?>
<shops>
    <shop>
	    <name>Amazon</name>
        <code>AMZ</code>
        <url>www.amazon.com</url>

        <product>
            <book>
                <name>Core JSF</name>
                <code>cojsf</code>
                <price>136</price>
                <pages>333</pages>
            </book>
        </product>
		
        <product>
            <book>
                <name>Java forr Dummies</name>
                <code>jfd</code>
                <price>68</price>
                <pages>400</pages>
            </book>
        </product>
		
        <product>
            <video>
                <name>Braveheart</name>
                <code>brvh</code>
                <price>15</price>
                <duration>3h</duration>
            </video>
        </product>
	
    </shop>
	<!-- <shop>Other types of shops</shop> -->
</shops>
Having the related classes below:
public class Shop {
	String name;
	String code;
	String url;
	Product[] productsArray;
}


public class Product {
	String name;
	String code;
	String price;
}

public class Book extends Product {
	String pages;
}

public class Video extends Product {
	String duration;
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 18 2009
Added on Nov 17 2009
2 comments
121 views