VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.
Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig
by jtuchel » Tue Jul 29, 2008 7:03 am
Hi there,
seems I can't figure this out myself...
I have an object model like this
object
+ list (OrderedCollection)
+ listItem
And I want to transport this in an XML stream that looks like this
<object>
<list>
<item no="1"></item>
<item no="2"></item>
</list>
</object>
It seems it's not possible to write xml with the <list></list> tags (in the docs this is called a wrapper tag). My mapping Spec says:
<ClassElementMapping ...>
<AttributeMapping ClassAttribute="list">
<SubElement>item</SubElement>
</AttributeMapping>
...</ClassElementMapping>
I've tried several clever and not so clever things, but it never writes out the wrapper tag.
Do I need a DTD for this purpose? Is there something I've not yet found?
Regards
Joachim
-
jtuchel
- [|]
-
- Posts: 245
- Joined: Fri Oct 05, 2007 1:05 am
- Location: Ludwigsburg, Germany
-
by Diane Engles » Wed Jul 30, 2008 5:13 am
Hello Joachim,
I've been working on updating the JrcOrderExample for Version 8 so that is easier to see how to create Xml output with the wrapper tag. You need to introduce class element mappings and a separate class for the list items. Below is a mapping spec:
- Code: Select all
<XmlMappingSpec Name="abtwsdl.map" NameSpaceURI="Vast">
<ClassElementMapping ElementTagName="Order" ClassName="JrcOrder">
<AttributeMapping ClassAttribute="number" >
<Attribute>number</Attribute>
</AttributeMapping>
<AttributeMapping ClassAttribute="status">
<Attribute>status</Attribute>
</AttributeMapping>
<AttributeMapping ClassAttribute="customer">
<SubElement>Customer</SubElement>
</AttributeMapping>
<AttributeMapping ClassAttribute="lineItems">
<SubElement>LineItems</SubElement>
</AttributeMapping>
</ClassElementMapping>
<ClassElementMapping ElementTagName="Customer" ClassName="JrcCustomer">
<AttributeMapping ClassAttribute="customerID">
<SubElement>CustomerID</SubElement>
</AttributeMapping>
<AttributeMapping ClassAttribute="contact">
<Attribute>Contact</Attribute>
</AttributeMapping>
<AttributeMapping ClassAttribute="address">
<SubElement>Address</SubElement>
</AttributeMapping>
<AttributeMapping ClassAttribute="phone">
<Attribute>Phone</Attribute>
</AttributeMapping>
</ClassElementMapping>
<ClassElementMapping ElementTagName="CustomerID" ClassName="JrcCustomerID">
<AttributeMapping ClassAttribute="number">
<Attribute>number</Attribute>
</AttributeMapping>
<AttributeMapping ClassAttribute="name">
<Attribute>namet</Attribute>
</AttributeMapping>
</ClassElementMapping>
<ClassElementMapping ElementTagName="Address" ClassName="JrcAddress">
<AttributeMapping ClassAttribute="street">
<Attribute>Street</Attribute>
</AttributeMapping>
<AttributeMapping ClassAttribute="city">
<Attribute>City</Attribute>
</AttributeMapping>
<AttributeMapping ClassAttribute="state">
<Attribute>State</Attribute>
</AttributeMapping>
<AttributeMapping ClassAttribute="postalCode">
<Attribute>PostalCode</Attribute>
</AttributeMapping>
<AttributeMapping ClassAttribute="country">
<Attribute>Country</Attribute>
</AttributeMapping>
</ClassElementMapping>
<ClassElementMapping ElementTagName="LineItem" ClassName="JrcLineItem">
<AttributeMapping ClassAttribute="quantity" StringConversionMethod="asNumber">
<Attribute>Quantity</Attribute>
</AttributeMapping>
<AttributeMapping ClassAttribute="item">
<SubElement>Item</SubElement>
</AttributeMapping>
<AttributeMapping ClassAttribute="number">
<Attribute>Number</Attribute>
</AttributeMapping>
</ClassElementMapping>
<ClassElementMapping ElementTagName="Item" ClassName="JrcItem">
<AttributeMapping ClassAttribute="number" >
<Attribute>Number</Attribute>
</AttributeMapping>
<AttributeMapping ClassAttribute="description">
<Attribute>Description</Attribute>
</AttributeMapping>
<AttributeMapping ClassAttribute="unitPrice">
<Attribute>UnitPrice</Attribute>
</AttributeMapping>
</ClassElementMapping>
</XmlMappingSpec>'.
That will result in the following output from the AbtXmlMappingParser:
- Code: Select all
'<Order number="O00001" status="Open">
<Customer>
<CustomerID name="Joe Akarski" number="C13579"></CustomerID>
<Address>
<Street>10 Main Street</Street>
<City>Anytown</City>
<State>AnyState</State>
<PostalCode>12345</PostalCode>
<Country>USA</Country>
</Address>
<Contact>Joe</Contact>
<Phone>555-1212</Phone>
</Customer>
<LineItems>
<LineItem number="1">
<Quantity>12</Quantity>
<Item number="I12345">
<Description>Roses</Description>
<UnitPrice>$3.50</UnitPrice>
</Item>
</LineItem>
<LineItem number="2">
<Quantity>1</Quantity>
<Item number="I67890">
<Description>Box of Candy</Description>
<UnitPrice>$5.50</UnitPrice>
</Item>
</LineItem>
<LineItem number="3">
<Quantity>1</Quantity>
<Item number="I4567">
<Description>Valentine''s Day Card</Description>
<UnitPrice>$2.99</UnitPrice>
</Item>
</LineItem>
</LineItems>
</Order>'
I will be happy to email a zip file with the entire example including a workspace and the Smalltalk classes to anyone who wants it.
-
Diane Engles
- Moderator
-
- Posts: 66
- Joined: Mon Oct 16, 2006 2:40 pm
-
by jtuchel » Wed Aug 06, 2008 5:12 am
Diane,
thanks a lot for your help. In fact, my error was not using a DTD or Schema, but only a mapping spec.
My code was correct, so were the xmls for mapping, I just have to add a schema to the game.
The docs aren't perfectly clear but there is a little warning that if you don't use both mapping spec and DTD/XSD, the results may differ.
Again, thanks!
-
jtuchel
- [|]
-
- Posts: 245
- Joined: Fri Oct 05, 2007 1:05 am
- Location: Ludwigsburg, Germany
-
by tc » Wed Aug 06, 2008 6:41 am
Hello,
Yes, a schema file (.xsd) is used to create ST classes in your designated app:
- Code: Select all
AbxXmlSchemaToClass new
createClassesFrom: 'd:\temp\vast xml\invoice.xsd'
in: MyAbtXmlSchemaClassesApp
replace: true
The schema file is also used to generate a mapping file:
- Code: Select all
AbxXmlSchemaToMappingFile new
createMappingFileNamed: 'd:\temp\vast xml\invoice.map'
from: 'd:\temp\vast xml\invoice.xsd'
Both the mapping spec and DOM tree are needed to create objects from the XML.
--tc
-
tc
- Moderator
-
- Posts: 304
- Joined: Tue Oct 17, 2006 7:40 am
- Location: Raleigh, NC
Return to VA Smalltalk 7.0, 7.5 & 8.0
Who is online
Users browsing this forum: Yahoo [Bot] and 1 guest