Search the web
Sign In
New User? Sign Up
xml-dbms
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Need help on Mapping language.   Message List  
Reply | Forward Message #3835 of 3867 |
RE: [xml-dbms] Need help on Mapping language.

Thanks for your help Ron. I switched to V2.0. I can't say I still
understand the mapping language well enough!





I was trying out the many-to-many relation example (actor/movie example
copy-paste from the FAQ page.) On MySQL, it somehow fails to insert the
second movie for actor ID=1. After updates this is how things look:



mysql> select * from joinmoviesactors;

+---------+---------+

| actorID | movieID |

+---------+---------+

| 1 | 2 |

| 2 | 2 |

| 3 | 1 |

+---------+---------+



Note: missing actorID=1 and movieID=1.





My mapping file:



===================================================================

<?xml version='1.0' ?>



<XMLToDBMS Version="2.0"
xmlns="http://www.xmlmiddleware.org/xmldbms/v2">

<Options>

<SimpleDateFormat Pattern="MM/dd/yyyy"
DefaultForTypes="DATE" />

</Options>

<Databases>

<Database Name="Default">

<Catalog>

<Schema>

<Table Name="actors">

<Column Name="id" DataType="INTEGER"
Nullable="No"/>

<Column Name="name"
DataType="VARCHAR" Length="255" Nullable="Yes"/>

<PrimaryKey>

<UseColumn Name="id"/>

</PrimaryKey>

</Table>




<Table Name="movies">

<Column Name="id" DataType="INTEGER"
Nullable="No"/>

<Column Name="title"
DataType="VARCHAR" Length="255" Nullable="Yes"/>

<PrimaryKey>

<UseColumn Name="id"/>

</PrimaryKey>

</Table>




<Table Name="joinmoviesactors">

<Column Name="actorID"
DataType="INTEGER" Nullable="No"/>

<Column Name="movieID"
DataType="INTEGER" Nullable="No"/>

<PrimaryKey>

<UseColumn Name="actorID"/>

<UseColumn Name="movieID"/>

</PrimaryKey>

<ForeignKey Name="actor_FK">

<UseTable Name="actors"/>

<UseUniqueKey
Name="PrimaryKey" />

<UseColumn Name="actorID"/>

</ForeignKey>

<ForeignKey Name="movies_FK">

<UseTable Name="movies"/>

<UseUniqueKey
Name="PrimaryKey" />

<UseColumn Name="movieID"/>

</ForeignKey>

</Table>




</Schema>

</Catalog>

</Database>

</Databases>



<Maps>

<ClassMap>

<ElementType Name="Actor"/>

<ToClassTable Name="actors"/>

<PropertyMap>

<Attribute Name="ID"/>

<ToColumn Name="id"/>

</PropertyMap>

<PropertyMap>

<ElementType Name="Name"/>

<ToColumn Name="name"/>

</PropertyMap>

<RelatedClass KeyInParentTable="Unique">

<ElementType Name="Movies" />

<UseUniqueKey Name="PrimaryKey" />

<UseForeignKey Name="actor_FK"/>

</RelatedClass>

</ClassMap>



<ClassMap>

<ElementType Name="Movies"/>

<ToClassTable Name="joinmoviesactors"/>

<RelatedClass KeyInParentTable="Foreign">

<ElementType Name="Movie" />

<UseUniqueKey Name="PrimaryKey" />

<UseForeignKey Name="movies_FK"/>

</RelatedClass>

</ClassMap>



<ClassMap>

<ElementType Name="Movie"/>

<ToClassTable Name="movies"/>

<PropertyMap>

<Attribute Name="ID"/>

<ToColumn Name="id"/>

</PropertyMap>

<PropertyMap>

<ElementType Name="Title"/>

<ToColumn Name="title"/>

</PropertyMap>

</ClassMap>



</Maps>

</XMLToDBMS>

===================================================================

Action file:



<Actions Version="2.0"
xmlns="http://www.xmlmiddleware.org/xmldbms/actions/v2">

<DefaultAction>

<Insert />

</DefaultAction>

<Action>

<ElementType Name="Movie"/>

<SoftInsert/>

</Action>

</Actions>







Thanks,

-Jay











________________________________

From: xml-dbms@yahoogroups.com [mailto:xml-dbms@yahoogroups.com] On
Behalf Of Ronald Bourret
Sent: Sunday, February 18, 2007 4:29 PM
To: xml-dbms@yahoogroups.com
Subject: Re: [xml-dbms] Need help on Mapping language.



No. To do this, you would need to use XSLT to transform the document
first. You would then map the transformed document to the database. In
your case, you would need to transform the document to the following:

<results>
<TableOne>
<id> 1 </id>
<data/>
</TableOne>
<TableTwo>
<id> 1 </id>
<data/>
</TableTwo>
</results>

Using XSLT with XML-DBMS is a fairly common occurrence. As a general
rule, the structure of the XML document needs to "match" the structure
of the database schema.

Note that you are also trying to do something else that is not supported

by XML-DBMS. In particular, the id element is a sibling of the table
elements. Elements mapped to columns must be children (or in some cases,

descendants) of elements mapped to tables.

-- Ron

P.S. I believe some commercial software, such as HiT Allora, can do what

you ask for.

Janardhan, Jay wrote:

> Thanks for the reply Ron.
>
>
>
> I'm switching to Java V2.0. While I start experimenting with V2.0, I
> have a quick question. Is it possible to map an element from the XML
> file to columns in different tables?
>
>
>
> For example,
>
>
>
> <results>
>
> <id> 1 </id>
>
> <TableOne>
>
> <data/>
>
> </TableOne>
>
> <TableTwo>
>
> <data/>
>
> </TableTwo>
>
> </results>
>
>
>
> Table: TableOne
>
> ID NOT NULL,
>
> Column1
>
> Coulmn2
>
>
>
> Table: TableTwo
>
> ID NOT NULL,
>
> Column1
>
>
>
> In this example, is it possible to map <id> (from the XML file) to
> TableOne::ID and TableTwo::ID?
>
> Appreciate your assistance.
>
> Thanks,
>
> -Jay





[Non-text portions of this message have been removed]




Mon Feb 26, 2007 11:01 pm

mrutyun
Offline Offline
Send Email Send Email

Forward
Message #3835 of 3867 |
Expand Messages Author Sort by Date

Hi Folks! My Input XML: <data> <key>1</<key> <data_source> <os>AIX</os> <version>5.2</version> </data_source> </data> Database has two tables: Table: data ... ...
Jay Janardhan
mrutyun
Offline Send Email
Feb 16, 2007
3:47 pm

Oops! I meant the "data_source::source_id" should get inserted into "data::source_id" not into "data::key". Sorry. ________________________________ From:...
Janardhan, Jay
mrutyun
Offline Send Email
Feb 16, 2007
3:51 pm

Hello, You are requesting two features that have limited or no support: 1) Insert data into the data_source table only if it does not already exist. This is...
Ronald Bourret
xmldbms
Offline Send Email
Feb 17, 2007
3:54 am

Thanks for the reply Ron. I'm switching to Java V2.0. While I start experimenting with V2.0, I have a quick question. Is it possible to map an element from the...
Janardhan, Jay
mrutyun
Offline Send Email
Feb 18, 2007
9:02 pm

No. To do this, you would need to use XSLT to transform the document first. You would then map the transformed document to the database. In your case, you...
Ronald Bourret
xmldbms
Offline Send Email
Feb 18, 2007
9:28 pm

Thanks for your help Ron. I switched to V2.0. I can't say I still understand the mapping language well enough! I was trying out the many-to-many relation...
Janardhan, Jay
mrutyun
Offline Send Email
Feb 26, 2007
11:02 pm

This is probably because the document shown in the FAQ isn't correct, as is noted in the IMPORTANT! paragraph. (When I discovered the error, I didn't have time...
Ronald Bourret
xmldbms
Offline Send Email
Feb 27, 2007
7:27 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help