How to bind to a brother XML node in Smooks configuration file?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to bind to a brother XML node in Smooks configuration file?

Kriss Lu

Hi all,

 

I 'd like to do xml->Java bean mapping. I fail to bind to a brother XML element.

 

How to refer bind "id" element in "SCHEDULE_GENERIC" element? I tried many solutions but no luck:

1) <jb:value property="id"       data="../id"/>

 2) <jb:value property="id"       data="#../id"/>

 3) <jb:value property="id"       data="./id"/>

 4) <jb:value property="id"       data="/GuideData/SCHEDULE/row/id"/>

 ......

Please see the configuration as below. Thanks in advance.

 

 

--------   XML file  ---------------

<GuideData>

                                <SCHEDULE>

                                                <row>

                                                                <id>100</STATION_NUM>

                                                                <!-- many other elements  -->

                                                                <SCHEDULE_GENERIC>Avatar_Movie</SCHEDULE_GENERIC>

                                                                <SCHEDULE_GENERIC>Avatar_Title</SCHEDULE_GENERIC>

                                                </row>

                </SCHEDULE>

</GuideData>

 

------- XML file  end -----------------------

 

---- smooks configurion file  --------------

<smooks-resource-list ...>   

                <jb:bean beanId="scheduleGenList" class="java.util.ArrayList" createOnElement="/GuideData/SCHEDULE/row">

        <jb:wiring  beanIdRef="scheduleGeneric" />

    </jb:bean>

               

                <jb:bean beanId="scheduleGeneric" class="kriss.GenericType" createOnElement="/GuideData/SCHEDULE/row/SCHEDULE_GENERIC">

        <jb:value property="id"       data="......"/>  ==> how to refer to <id> element?       

        <jb:value property="content"  data="#/"/>

    </jb:bean>

</smooks-resource-list>

 

--------smooks configurion file end ---------

 

-----kriss.GenericType class ----

public calss GenericType {

                public String id;

                public String content;

                //skips getter/setter methods..

}

-----kriss.GenericType class end ----

 

 

 

Best Regards,

Kriss

 

Reply | Threaded
Open this post in threaded view
|

Re: How to bind to a brother XML node in Smooks configuration file?

Tom Fennelly
I think you might have the config a bit wrong.

You have:

<jb:bean beanId="scheduleGenList" class="java.util.ArrayList" createOnElement="/GuideData/SCHEDULE/row">

        <jb:wiring  beanIdRef="scheduleGeneric" />

</jb:bean>


<jb:bean beanId="scheduleGeneric" class="kriss.GenericType" createOnElement="/GuideData/SCHEDULE/row/SCHEDULE_GENERIC">

        <jb:value property="id"       data="......"/>  ==> how to refer to <id> element?       


       etc...       


</jb:bean>

I think you should have:

<jb:bean beanId="scheduleGenList" class="java.util.ArrayList" createOnElement="/GuideData/SCHEDULE">

    <jb:wiring  beanIdRef="scheduleGeneric" />

</jb:bean>


<jb:bean beanId="scheduleGeneric" class="kriss.GenericType" createOnElement="/GuideData/SCHEDULE/row">

    <jb:value property="id"       data="/GuideData/SCHEDULE/row/id"/>

       
        etc...

</jb:bean>





On 07/11/2013 13:45, Kriss Lu wrote:

Hi all,

 

I 'd like to do xml->Java bean mapping. I fail to bind to a brother XML element.

 

How to refer bind "id" element in "SCHEDULE_GENERIC" element? I tried many solutions but no luck:

1) <jb:value property="id"       data="../id"/>

 2) <jb:value property="id"       data="#../id"/>

 3) <jb:value property="id"       data="./id"/>

 4) <jb:value property="id"       data="/GuideData/SCHEDULE/row/id"/>

 ......

Please see the configuration as below. Thanks in advance.

 

 

--------   XML file  ---------------

<GuideData>

                                <SCHEDULE>

                                                <row>

                                                                <id>100</STATION_NUM>

                                                                <!-- many other elements  -->

                                                                <SCHEDULE_GENERIC>Avatar_Movie</SCHEDULE_GENERIC>

                                                                <SCHEDULE_GENERIC>Avatar_Title</SCHEDULE_GENERIC>

                                                </row>

                </SCHEDULE>

</GuideData>

 

------- XML file  end -----------------------

 

---- smooks configurion file  --------------

<smooks-resource-list ...>   

                <jb:bean beanId="scheduleGenList" class="java.util.ArrayList" createOnElement="/GuideData/SCHEDULE/row">

        <jb:wiring  beanIdRef="scheduleGeneric" />

    </jb:bean>

               

                <jb:bean beanId="scheduleGeneric" class="kriss.GenericType" createOnElement="/GuideData/SCHEDULE/row/SCHEDULE_GENERIC">

        <jb:value property="id"       data="......"/>  ==> how to refer to <id> element?       

        <jb:value property="content"  data="#/"/>

    </jb:bean>

</smooks-resource-list>

 

--------smooks configurion file end ---------

 

-----kriss.GenericType class ----

public calss GenericType {

                public String id;

                public String content;

                //skips getter/setter methods..

}

-----kriss.GenericType class end ----

 

 

 

Best Regards,

Kriss

 


Reply | Threaded
Open this post in threaded view
|

RE: How to bind to a brother XML node in Smooks configuration file?

Kriss Lu

Hi Tom,

 

Thanks for you quick response.  Your suggested configuration only fetch the last  “SCHEDULE_GENERIC” which  is not what I expect.

 

Let me clarify more here.

 

Take the bellowing XML file as an example:

--------   XML file  ---------------

<GuideData>

<SCHEDULE>

                                <row>

                                                <id>100</STATION_NUM>

                                                <!-- many other elements  -->

                                                <SCHEDULE_GENERIC>Movie_A</SCHEDULE_GENERIC>

                                                <SCHEDULE_GENERIC>Movie_B</SCHEDULE_GENERIC>

                                </row>

                                <row>

                                                <id>101</STATION_NUM>

                                                <!-- many other elements  -->

                                                <SCHEDULE_GENERIC>Movie_C</SCHEDULE_GENERIC>

                                                <SCHEDULE_GENERIC>Movie_D</SCHEDULE_GENERIC>

                                </row>

                                <!—more rows here--->

                </SCHEDULE>

</GuideData>

------- XML file  end -----------------------

 

After Smooks processing, I want to get 2 beans:

a)      one is a list of “SCHEDULE” row but not include the “SCHEDULE_GENERIC”.  

b)      The other one is a list of “SCHEDULE_GENERIC” which may distribute in different “SCHEDULE” rows.

 

Suppose these 2 beans are name “scheduleList” and “scheduleGenericList” respectively. Here are the result I expect:

scheduleList.size()                           => 2

                scheduleList.get(0).id                    = >100

                scheduleList.get(1).id                    => 101

 

                scheduleGenericList.size()                           =>    4       yes. I want to hold all the SCHEDULE_GENERIC items in scheduleGenericList

                scheduleGenericList.get(0).id                   =>        100

                scheduleGenericList.get(0).content        =>   Movie_A

                scheduleGenericList.get(1).id                   =>        100

                scheduleGenericList.get(1).content        =>   Movie_B

                scheduleGenericList.get(2).id                   =>        101

                scheduleGenericList.get(2).content        =>   Movie_C

                scheduleGenericList.get(3).id                   =>        101

                scheduleGenericList.get(3).content        =>   Movie_D

 

In fact, I know how to define “scheduleList “ bean in Smooks, but how about “scheduleGenericList” ? How to define it?  I find all the list/collection examples of Smooks in Internet have a pre-condition: the list items are under the same XML element.

 

 

Your help are greatly appreciated!  Thanks.

 

BR//Kriss

 

 

From: Tom Fennelly [mailto:[hidden email]]
Sent: Thursday, November 07, 2013 11:27 PM
To: [hidden email]
Subject: Re: [milyn-user] How to bind to a brother XML node in Smooks configuration file?

 

I think you might have the config a bit wrong.

You have:

<jb:bean beanId="scheduleGenList" class="java.util.ArrayList" createOnElement="/GuideData/SCHEDULE/row">

        <jb:wiring  beanIdRef="scheduleGeneric" />

</jb:bean>

 

<jb:bean beanId="scheduleGeneric" class="kriss.GenericType" createOnElement="/GuideData/SCHEDULE/row/SCHEDULE_GENERIC">

        <jb:value property="id"       data="......"/>  ==> how to refer to <id> element?       


       etc...       

 

</jb:bean>

I think you should have:

<jb:bean beanId="scheduleGenList" class="java.util.ArrayList" createOnElement="/GuideData/SCHEDULE">

    <jb:wiring  beanIdRef="scheduleGeneric" />

</jb:bean>

 

<jb:bean beanId="scheduleGeneric" class="kriss.GenericType" createOnElement="/GuideData/SCHEDULE/row">

    <jb:value property="id"       data="/GuideData/SCHEDULE/row/id"/>

       
        etc...

</jb:bean>




On 07/11/2013 13:45, Kriss Lu wrote:

Hi all,

 

I 'd like to do xml->Java bean mapping. I fail to bind to a brother XML element.

 

How to refer bind "id" element in "SCHEDULE_GENERIC" element? I tried many solutions but no luck:

1) <jb:value property="id"       data="../id"/>

 2) <jb:value property="id"       data="#../id"/>

 3) <jb:value property="id"       data="./id"/>

 4) <jb:value property="id"       data="/GuideData/SCHEDULE/row/id"/>

 ......

Please see the configuration as below. Thanks in advance.

 

 

--------   XML file  ---------------

<GuideData>

                                <SCHEDULE>

                                                <row>

                                                                <id>100</STATION_NUM>

                                                                <!-- many other elements  -->

                                                                <SCHEDULE_GENERIC>Avatar_Movie</SCHEDULE_GENERIC>

                                                                <SCHEDULE_GENERIC>Avatar_Title</SCHEDULE_GENERIC>

                                                </row>

                </SCHEDULE>

</GuideData>

 

------- XML file  end -----------------------

 

---- smooks configurion file  --------------

<smooks-resource-list ...>   

                <jb:bean beanId="scheduleGenList" class="java.util.ArrayList" createOnElement="/GuideData/SCHEDULE/row">

        <jb:wiring  beanIdRef="scheduleGeneric" />

    </jb:bean>

               

                <jb:bean beanId="scheduleGeneric" class="kriss.GenericType" createOnElement="/GuideData/SCHEDULE/row/SCHEDULE_GENERIC">

        <jb:value property="id"       data="......"/>  ==> how to refer to <id> element?       

        <jb:value property="content"  data="#/"/>

    </jb:bean>

</smooks-resource-list>

 

--------smooks configurion file end ---------

 

-----kriss.GenericType class ----

public calss GenericType {

                public String id;

                public String content;

                //skips getter/setter methods..

}

-----kriss.GenericType class end ----

 

 

 

Best Regards,

Kriss

 

 

Reply | Threaded
Open this post in threaded view
|

Re: How to bind to a brother XML node in Smooks configuration file?

Tom Fennelly
Ah ok... sorry... I get what you're trying to do.

In that case I think you need to capture the current id using a <jb:value> config (http://goo.gl/SCDzN), and then wire that into the objects, which are in turn wired into the lists.  So something like...

<jb:bean beanId="scheduleGenList" class="java.util.ArrayList" createOnElement="/GuideData/SCHEDULE/row">

        <jb:wiring  beanIdRef="scheduleGeneric" />

</jb:bean>


<jb:value beanId="id"  data="/GuideData/SCHEDULE/row/id"/>

 

<jb:bean beanId="scheduleGeneric" class="kriss.GenericType" createOnElement="/GuideData/SCHEDULE/row/SCHEDULE_GENERIC">

        <jb:wiring  property="id" beanIdRef="beanId" />

     <jb:value property="content" data="/GuideData/SCHEDULE/row/SCHEDULE_GENERIC" />

</jb:bean>




On 08/11/2013 06:41, Kriss Lu wrote:

Hi Tom,

 

Thanks for you quick response.  Your suggested configuration only fetch the last  “SCHEDULE_GENERIC” which  is not what I expect.

 

Let me clarify more here.

 

Take the bellowing XML file as an example:

--------   XML file  ---------------

<GuideData>

<SCHEDULE>

                                <row>

                                                <id>100</STATION_NUM>

                                                <!-- many other elements  -->

                                                <SCHEDULE_GENERIC>Movie_A</SCHEDULE_GENERIC>

                                                <SCHEDULE_GENERIC>Movie_B</SCHEDULE_GENERIC>

                                </row>

                                <row>

                                                <id>101</STATION_NUM>

                                                <!-- many other elements  -->

                                                <SCHEDULE_GENERIC>Movie_C</SCHEDULE_GENERIC>

                                                <SCHEDULE_GENERIC>Movie_D</SCHEDULE_GENERIC>

                                </row>

                                <!—more rows here--->

                </SCHEDULE>

</GuideData>

------- XML file  end -----------------------

 

After Smooks processing, I want to get 2 beans:

a)      one is a list of “SCHEDULE” row but not include the “SCHEDULE_GENERIC”.  

b)      The other one is a list of “SCHEDULE_GENERIC” which may distribute in different “SCHEDULE” rows.

 

Suppose these 2 beans are name “scheduleList” and “scheduleGenericList” respectively. Here are the result I expect:

scheduleList.size()                           => 2

                scheduleList.get(0).id                    = >100

                scheduleList.get(1).id                    => 101

 

                scheduleGenericList.size()                           =>    4       yes. I want to hold all the SCHEDULE_GENERIC items in scheduleGenericList

                scheduleGenericList.get(0).id                   =>        100

                scheduleGenericList.get(0).content        =>   Movie_A

                scheduleGenericList.get(1).id                   =>        100

                scheduleGenericList.get(1).content        =>   Movie_B

                scheduleGenericList.get(2).id                   =>        101

                scheduleGenericList.get(2).content        =>   Movie_C

                scheduleGenericList.get(3).id                   =>        101

                scheduleGenericList.get(3).content        =>   Movie_D

 

In fact, I know how to define “scheduleList “ bean in Smooks, but how about “scheduleGenericList” ? How to define it?  I find all the list/collection examples of Smooks in Internet have a pre-condition: the list items are under the same XML element.

 

 

Your help are greatly appreciated!  Thanks.

 

BR//Kriss

 

 

From: Tom Fennelly [[hidden email]]
Sent: Thursday, November 07, 2013 11:27 PM
To: [hidden email]
Subject: Re: [milyn-user] How to bind to a brother XML node in Smooks configuration file?

 

I think you might have the config a bit wrong.

You have:

<jb:bean beanId="scheduleGenList" class="java.util.ArrayList" createOnElement="/GuideData/SCHEDULE/row">

        <jb:wiring  beanIdRef="scheduleGeneric" />

</jb:bean>

 

<jb:bean beanId="scheduleGeneric" class="kriss.GenericType" createOnElement="/GuideData/SCHEDULE/row/SCHEDULE_GENERIC">

        <jb:value property="id"       data="......"/>  ==> how to refer to <id> element?       


       etc...       

 

</jb:bean>

I think you should have:

<jb:bean beanId="scheduleGenList" class="java.util.ArrayList" createOnElement="/GuideData/SCHEDULE">

    <jb:wiring  beanIdRef="scheduleGeneric" />

</jb:bean>

 

<jb:bean beanId="scheduleGeneric" class="kriss.GenericType" createOnElement="/GuideData/SCHEDULE/row">

    <jb:value property="id"       data="/GuideData/SCHEDULE/row/id"/>

       
        etc...

</jb:bean>




On 07/11/2013 13:45, Kriss Lu wrote:

Hi all,

 

I 'd like to do xml->Java bean mapping. I fail to bind to a brother XML element.

 

How to refer bind "id" element in "SCHEDULE_GENERIC" element? I tried many solutions but no luck:

1) <jb:value property="id"       data="../id"/>

 2) <jb:value property="id"       data="#../id"/>

 3) <jb:value property="id"       data="./id"/>

 4) <jb:value property="id"       data="/GuideData/SCHEDULE/row/id"/>

 ......

Please see the configuration as below. Thanks in advance.

 

 

--------   XML file  ---------------

<GuideData>

                                <SCHEDULE>

                                                <row>

                                                                <id>100</STATION_NUM>

                                                                <!-- many other elements  -->

                                                                <SCHEDULE_GENERIC>Avatar_Movie</SCHEDULE_GENERIC>

                                                                <SCHEDULE_GENERIC>Avatar_Title</SCHEDULE_GENERIC>

                                                </row>

                </SCHEDULE>

</GuideData>

 

------- XML file  end -----------------------

 

---- smooks configurion file  --------------

<smooks-resource-list ...>   

                <jb:bean beanId="scheduleGenList" class="java.util.ArrayList" createOnElement="/GuideData/SCHEDULE/row">

        <jb:wiring  beanIdRef="scheduleGeneric" />

    </jb:bean>

               

                <jb:bean beanId="scheduleGeneric" class="kriss.GenericType" createOnElement="/GuideData/SCHEDULE/row/SCHEDULE_GENERIC">

        <jb:value property="id"       data="......"/>  ==> how to refer to <id> element?       

        <jb:value property="content"  data="#/"/>

    </jb:bean>

</smooks-resource-list>

 

--------smooks configurion file end ---------

 

-----kriss.GenericType class ----

public calss GenericType {

                public String id;

                public String content;

                //skips getter/setter methods..

}

-----kriss.GenericType class end ----

 

 

 

Best Regards,

Kriss

 

 


Reply | Threaded
Open this post in threaded view
|

RE: How to bind to a brother XML node in Smooks configuration file?

Kriss Lu

Thanks Tom!  I will have a try. Thanks for your help! J

 

From: Tom Fennelly [mailto:[hidden email]]
Sent: Friday, November 08, 2013 3:57 PM
To: [hidden email]
Subject: Re: [milyn-user] How to bind to a brother XML node in Smooks configuration file?

 

Ah ok... sorry... I get what you're trying to do.

In that case I think you need to capture the current id using a <jb:value> config (http://goo.gl/SCDzN), and then wire that into the objects, which are in turn wired into the lists.  So something like...

<jb:bean beanId="scheduleGenList" class="java.util.ArrayList" createOnElement="/GuideData/SCHEDULE/row">

        <jb:wiring  beanIdRef="scheduleGeneric" />

</jb:bean>


<jb:value beanId="id"  data="/GuideData/SCHEDULE/row/id"/>

 

<jb:bean beanId="scheduleGeneric" class="kriss.GenericType" createOnElement="/GuideData/SCHEDULE/row/SCHEDULE_GENERIC">

        <jb:wiring  property="id" beanIdRef="beanId" />

     <jb:value property="content" data="/GuideData/SCHEDULE/row/SCHEDULE_GENERIC" />

</jb:bean>



On 08/11/2013 06:41, Kriss Lu wrote:

Hi Tom,

 

Thanks for you quick response.  Your suggested configuration only fetch the last  “SCHEDULE_GENERIC” which  is not what I expect.

 

Let me clarify more here.

 

Take the bellowing XML file as an example:

--------   XML file  ---------------

<GuideData>

<SCHEDULE>

                                <row>

                                                <id>100</STATION_NUM>

                                                <!-- many other elements  -->

                                                <SCHEDULE_GENERIC>Movie_A</SCHEDULE_GENERIC>

                                                <SCHEDULE_GENERIC>Movie_B</SCHEDULE_GENERIC>

                                </row>

                                <row>

                                                <id>101</STATION_NUM>

                                                <!-- many other elements  -->

                                                <SCHEDULE_GENERIC>Movie_C</SCHEDULE_GENERIC>

                                                <SCHEDULE_GENERIC>Movie_D</SCHEDULE_GENERIC>

                                </row>

                                <!—more rows here--->

                </SCHEDULE>

</GuideData>

------- XML file  end -----------------------

 

After Smooks processing, I want to get 2 beans:

a)      one is a list of “SCHEDULE” row but not include the “SCHEDULE_GENERIC”.  

b)      The other one is a list of “SCHEDULE_GENERIC” which may distribute in different “SCHEDULE” rows.

 

Suppose these 2 beans are name “scheduleList” and “scheduleGenericList” respectively. Here are the result I expect:

scheduleList.size()                           => 2

                scheduleList.get(0).id                    = >100

                scheduleList.get(1).id                    => 101

 

                scheduleGenericList.size()                           =>    4       yes. I want to hold all the SCHEDULE_GENERIC items in scheduleGenericList

                scheduleGenericList.get(0).id                   =>        100

                scheduleGenericList.get(0).content        =>   Movie_A

                scheduleGenericList.get(1).id                   =>        100

                scheduleGenericList.get(1).content        =>   Movie_B

                scheduleGenericList.get(2).id                   =>        101

                scheduleGenericList.get(2).content        =>   Movie_C

                scheduleGenericList.get(3).id                   =>        101

                scheduleGenericList.get(3).content        =>   Movie_D

 

In fact, I know how to define “scheduleList “ bean in Smooks, but how about “scheduleGenericList” ? How to define it?  I find all the list/collection examples of Smooks in Internet have a pre-condition: the list items are under the same XML element.

 

 

Your help are greatly appreciated!  Thanks.

 

BR//Kriss

 

 

From: Tom Fennelly [[hidden email]]
Sent: Thursday, November 07, 2013 11:27 PM
To: [hidden email]
Subject: Re: [milyn-user] How to bind to a brother XML node in Smooks configuration file?

 

I think you might have the config a bit wrong.

You have:

<jb:bean beanId="scheduleGenList" class="java.util.ArrayList" createOnElement="/GuideData/SCHEDULE/row">

        <jb:wiring  beanIdRef="scheduleGeneric" />

</jb:bean>

 

<jb:bean beanId="scheduleGeneric" class="kriss.GenericType" createOnElement="/GuideData/SCHEDULE/row/SCHEDULE_GENERIC">

        <jb:value property="id"       data="......"/>  ==> how to refer to <id> element?       


       etc...       

 

</jb:bean>

I think you should have:

<jb:bean beanId="scheduleGenList" class="java.util.ArrayList" createOnElement="/GuideData/SCHEDULE">

    <jb:wiring  beanIdRef="scheduleGeneric" />

</jb:bean>

 

<jb:bean beanId="scheduleGeneric" class="kriss.GenericType" createOnElement="/GuideData/SCHEDULE/row">

    <jb:value property="id"       data="/GuideData/SCHEDULE/row/id"/>

       
        etc...

</jb:bean>





On 07/11/2013 13:45, Kriss Lu wrote:

Hi all,

 

I 'd like to do xml->Java bean mapping. I fail to bind to a brother XML element.

 

How to refer bind "id" element in "SCHEDULE_GENERIC" element? I tried many solutions but no luck:

1) <jb:value property="id"       data="../id"/>

 2) <jb:value property="id"       data="#../id"/>

 3) <jb:value property="id"       data="./id"/>

 4) <jb:value property="id"       data="/GuideData/SCHEDULE/row/id"/>

 ......

Please see the configuration as below. Thanks in advance.

 

 

--------   XML file  ---------------

<GuideData>

                                <SCHEDULE>

                                                <row>

                                                                <id>100</STATION_NUM>

                                                                <!-- many other elements  -->

                                                                <SCHEDULE_GENERIC>Avatar_Movie</SCHEDULE_GENERIC>

                                                                <SCHEDULE_GENERIC>Avatar_Title</SCHEDULE_GENERIC>

                                                </row>

                </SCHEDULE>

</GuideData>

 

------- XML file  end -----------------------

 

---- smooks configurion file  --------------

<smooks-resource-list ...>   

                <jb:bean beanId="scheduleGenList" class="java.util.ArrayList" createOnElement="/GuideData/SCHEDULE/row">

        <jb:wiring  beanIdRef="scheduleGeneric" />

    </jb:bean>

               

                <jb:bean beanId="scheduleGeneric" class="kriss.GenericType" createOnElement="/GuideData/SCHEDULE/row/SCHEDULE_GENERIC">

        <jb:value property="id"       data="......"/>  ==> how to refer to <id> element?       

        <jb:value property="content"  data="#/"/>

    </jb:bean>

</smooks-resource-list>

 

--------smooks configurion file end ---------

 

-----kriss.GenericType class ----

public calss GenericType {

                public String id;

                public String content;

                //skips getter/setter methods..

}

-----kriss.GenericType class end ----

 

 

 

Best Regards,

Kriss