RE: WOXMLDecoder
RE: WOXMLDecoder
- Subject: RE: WOXMLDecoder
- From: "Clark, Igor" <email@hidden>
- Date: Wed, 28 Jul 2004 11:59:13 +0100
Hi Baiss,
The mapping model format can accommodate relationships between EO objects,
and WOXMLDecoder relates the objects it finds according to the mapping
model's rules.
<entity name="JavaTransactionClass" xmlTag="Transaction"
ignoreUnmappedTags="NO">
<property name="transactionAttribute" xmlTag="Attribute" />
<property name="category" xmlTag="Category" forceList="YES"
/>
</entity>
<entity name="JavaCategoryClass" xmlTag="Category"
ignoreUnmappedTags="NO">
<property name="categoryAttribute" xmlTag="Attribute" />
</entity>
Something like this will enable your WOXMLDecoder to make the relationships.
Note you should use forceList="YES" if it's a to-many relationship. There's
some discussion of this in "The Format of the Mapping Model" in the
com.webobjects.appserver.xml package description.
Secondly. re your error, are you inserting all the objects retrieved from
the XML file into the editing context?
I have this error if I don't traverse all the relationships, from the root
element down to the very last leaf, and insert each resulting object into
the EC. It's because the objects are all already related to each other
according to the data in the XML file and the relationships in the mapping
model. The reason your Transaction object has no Gid seems likely to be that
it's not in an EC - if it is and you try to save it with other objects
related and they have no Gid, ec.saveChanges() will find this problem.
WRT the "create a category record if none found", I think you'd have to do
this by hand. The WOXMLDecoder will create interrelated EOs in memory to
represent the data found in the XML file according to the mapping model
rules; if the data in the XML file does not contain the category, it's then
up to your code to retrieve one from the database / make up a new one (as
required) and relate it to the appropriate EO.
Any use?
Igor
-----Original Message-----
From: Baiss Eric Magnusson [mailto:email@hidden]
Sent: 27 July 2004 18:24
To: Clark, Igor
Cc: WebObjectsDev
Subject: Re: WOXMLDecoder
Thanks Igor,
That looks good, it does seem to solve the multiple objects problem I
had.
I had fixed the model to get rid of the KeyWord as a child of entity
Transaction, although eventually I would like to be able to handle my
many-to-many relationship between transactions and keys within XML and
need to understand the appropriate XML syntax to do such.
But note from the dump of a record:
{values = {transId = <com.webobjects.foundation.NSKeyValueCoding$Null>;
loginId = <com.webobjects.foundation.NSKeyValueCoding$Null>;
toWho = "null"; vendor = "Apewx"; isBusiness = "1"; toAccount =
"null"; date = 2004-06-15 03:34:39 Etc/GMT; toCategory = "null";
personId = <com.webobjects.foundation.NSKeyValueCoding$Null>;
curValue = <com.webobjects.foundation.NSKeyValueCoding$Null>;
expTypeId = <com.webobjects.foundation.NSKeyValueCoding$Null>;
toSubCategory = "null"; subCatId =
<com.webobjects.foundation.NSKeyValueCoding$Null>;
toExpenseType = "null"; amount = 6.00; transDescr =
<com.webobjects.foundation.NSKeyValueCoding$Null>; numShares =
<com.webobjects.foundation.NSKeyValueCoding$Null>;
accountId = <com.webobjects.foundation.NSKeyValueCoding$Null>;
keyWords = "null"; catId =
<com.webobjects.foundation.NSKeyValueCoding$Null>; };
this = "<Transaction a944b0 [Gid Not Found]>"; },
I need something I don't think I can get from <WOXMLDecoder>, which is
that the <transaction> record refers to a <category> record, i.e. the
XML parsing would have to create in the transaction EO a link to the
category record, and create a category record if none was found, the
same goes for all the other relationships.
Note: I have 2 reasons for doing this project:
1) I want to be able to set up a demo client and erase and restore the
client with different dates, about a 1000 transactions.
2) I want to be prepared for the hoped for eventuality of the banks
providing XML of the account transactions, rather than the QIF they now
"somewhat" supply.
But here's a partial dump of the resOn Jul 26, 2004, at 3:15 AM, Clark,
Igor wrote:
> The XML document should have a root element, which you can use as a
> "container" for the collection of transaction records. Use a mapping
> model
> to specify how the XML transactions should be converted into your
> transaction objects, and decode the root object as this container. I've
> often used this sort of model:
>
> <entity name="com.webobjects.foundation.NSMutableDictionary"
> xmlTag="Transaction_List" ignoreUnmappedTags="YES"
> contentsKey="transactionList" />
>
> <entity name="JavaTransactionClass" xmlTag="Transaction"
> ignoreUnmappedTags="NO">
> <property name="attribute" xmlTag="Value" />
> </entity>
>
> for XML data files like
>
> <Transaction_List>
> <Transaction>
> <Value>AABBCC</Value>
> </Transaction>
> <Transaction>
> <Value>AABBCC</Value>
> </Transaction>
> </Transaction_List>
>
> and used it thus:
>
> WOXMLDecoder decoder; // assume exists
> created with mapping model as above
> NSMutableDictionary dict =
> (NSMutableDictionary)decoder.decodeRootObject(yourXmlFile);
> NSMutableArray transactions =
> (NSMutableArray)dict.objectForKey("transactionList");
>
> "transactions" now contains your JavaTransactionClass objects.
>
> The way the WOXML[De]Coders work seems a bit arcane sometimes and the
> documentation is pitiful but this definitely works for me.
>
> HTH
> Igor
>
> -----Original Message-----
> From: Baiss Eric Magnusson [mailto:email@hidden]
> Sent: 24 July 2004 00:23
>
> Would anyone disagree with the following?
>
> If you have a XML file that you want to decode into many EO's of the
> same type, you can't use WOXMLDecoder, as it is intended for single
> object decoding only.
>
----
Baiss Eric Magnusson
<http://www.Track-Your-Finances.com>
<http://www.CascadeWebDesign.com>
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.