You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by kiran vuppla <ki...@yahoo.com> on 2008/04/14 16:09:57 UTC

Reading xml file

I have an xml file and want to store in to an IBatis object. Please let me know if any one has any solution to write the SQL.

XML FILE:

<content>
  <talent>
    <image>/images/test1.gif</image>
    <imageAltText>testImageAltText</imageAltText>
    <links>
    <link>/urls/link1.html</link>
    <text>link1</text>
    </links>
    <links>
    <link>/urls/link2.html</link>
    <text>link2</text>
    </links>
   </talent>
  <talent>
    <image>/images/test2.gif</image>
    <imageAltText>testImageAltText2</imageAltText>
    <links>
    <link>/urls/link3.html</link>
    <text>link3</text>
    </links>
    <links>
    <link>/urls/link4.html</link>
    <text>link4</text>
    </links>
   </talent>
  </content>

IBATIS RESULT MUST BE:

   <resultMap class="com.test.domain.MainModule" id="MainModuleResultObject" groupBy="id">
    <result property="modules" resultMap="module.ModuleResults"/>
   </resultMap>

   <resultMap class="com.test.domain.Module" id="ModuleResults" groupBy="id">
      <result property="id" column="ID"/>
       <result property="titleImageURL" column="IMG_URL"/>
       <result property="titleImageAltText" column="IMG_ALT_TEXT"/>
       <result property="moduleElements" resultMap="module.ModuleElementResult"/>       
    </resultMap>

   <resultMap class="com.test.domain.ModuleElement" id="ModuleElementResult">
            <result property="link" column="LINK"/>
            <result property="text" column="TEXT"/>
    </resultMap>

 If some one can help me out in writing SQL to return the result in the above format that would be grateful.

 Thanks in advance for your time.
 Kiran
 
        

Re: Reading xml file

Posted by Brandon Goodin <br...@gmail.com>.
Based on what you are asking I'm assuming you are quite new to programming.

What database are you using?
Have you researched if it has any facilities for handling XML? (i.e. Oracle)

iBATIS works with objects. So, it may be wise to parse the XML into Java
POJOs and then save those object into the database. After that you can
select the data out into the same POJOs.

Brandon Goodin

On Mon, Apr 14, 2008 at 9:09 AM, kiran vuppla <ki...@yahoo.com>
wrote:

>
> I have an xml file and want to store in to an IBatis object. Please let me
> know if any one has any solution to write the SQL.
>
> XML FILE:
>
> <content>
>   <talent>
>     <image>/images/test1.gif</image>
>     <imageAltText>testImageAltText</imageAltText>
>     <links>
>     <link>/urls/link1.html</link>
>     <text>link1</text>
>     </links>
>     <links>
>     <link>/urls/link2.html</link>
>     <text>link2</text>
>     </links>
>    </talent>
>   <talent>
>     <image>/images/test2.gif</image>
>     <imageAltText>testImageAltText2</imageAltText>
>     <links>
>     <link>/urls/link3.html</link>
>     <text>link3</text>
>     </links>
>     <links>
>     <link>/urls/link4.html</link>
>     <text>link4</text>
>     </links>
>    </talent>
>   </content>
>
> IBATIS RESULT MUST BE:
>
>    <resultMap class="com.test.domain.MainModule"
> id="MainModuleResultObject" groupBy="id">
>     <result property="modules" resultMap="module.ModuleResults"/>
>    </resultMap>
>
>    <resultMap class="com.test.domain.Module" id="ModuleResults"
> groupBy="id">
>       <result property="id" column="ID"/>
>        <result property="titleImageURL" column="IMG_URL"/>
>        <result property="titleImageAltText" column="IMG_ALT_TEXT"/>
>        <result property="moduleElements"
> resultMap="module.ModuleElementResult"/>
>     </resultMap>
>
>    <resultMap class="com.test.domain.ModuleElement"
> id="ModuleElementResult">
>             <result property="link" column="LINK"/>
>             <result property="text" column="TEXT"/>
>     </resultMap>
>
>  If some one can help me out in writing SQL to return the result in the
> above format that would be grateful.
>
>  Thanks in advance for your time.
>  Kiran
>
>
>