Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > ID and IDREF Files

Reply
Thread Tools

ID and IDREF Files

 
 
geoff
Guest
Posts: n/a
 
      12-02-2007
This is how the book has the files (3 of them) but xml notepad says shipTo
has to be filled out, I hate it when book examples do not work


======== INVOICE.XML ==========

<?xml version="1.0" encoding="UTF-8"?>
<invoice:invoice xmlns:invoice="http://www.skatestown.com/ns/invoice"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.skatestown.com/ns/invoice
./invoice.xsd"
id="43871" submitted="2004-01-05" customerId="73852">
<billTo id="addr-1">
<company>The Skateboard Warehouse</company>
<street>One Warehouse Park</street>
<street>Building 17</street>
<city>Boston</city>
<state>MA</state>
<postalCode>01775</postalCode>
</billTo>
<shipTo href="addr-1"/>
<order>
<item sku="318-BP" quantity="5" unitPrice="49.95">
<description>Skateboard backpack; five pockets</description>
</item>
<item sku="947-TI" quantity="12" unitPrice="129.00">
<description>Street-style titanium skateboard.</description>
</item>
<item sku="008-PR" quantity="1000" unitPrice="0.00">
<description>Promotional: SkatesTown stickers</description>
</item>
</order>
<tax>89.89</tax>
<shippingAndHandling>200</shippingAndHandling>
<totalCost>2087.64</totalCost>
</invoice:invoice>



======== INVOICE.XSD ==========

<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema
targetNamespace="http://www.skatestown.com/ns/invoice"
xmlnso="http://www.skatestown.com/ns/po"
xmlnssd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.skatestown.com/ns/invoice">

<xsd:import namespace="http://www.skatestown.com/ns/po"
schemaLocation="./po.xsd" />
<xsd:annotation>
<xsd:documentation xml:lang="en">
Invoice schema for SkatesTown.
</xsd:documentation>
</xsd:annotation>
<xsd:element name="invoice" type="invoiceType" />
<xsd:complexType name="invoiceType">
<xsd:sequence>
<xsd:element name="billTo" type="po:addressType" />
<xsd:element name="shipTo" type="po:addressType" />
<xsd:element name="order">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="item" type="itemType" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="tax" type="priceType" />
<xsd:element name="shippingAndHandling" type="priceType" />
<xsd:element name="totalCost" type="priceType" />
</xsd:sequence>
<xsd:attribute name="id" type="xsdositiveInteger" use="required" />
<xsd:attribute name="submitted" type="xsd:date" use="required" />
<xsd:attribute name="customerId" type="xsdositiveInteger" use="required"
/>
</xsd:complexType>
<xsd:complexType name="itemType">
<xsd:complexContent>
<xsd:extension base="po:itemType">
<xsd:attribute name="unitPrice" type="priceType" use="required" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:simpleType name="priceType">
<xsd:restriction base="xsd:decimal">
<xsd:minInclusive value="0" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>


========== PO.XSD =========

<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns="http://www.skatestown.com/ns/po"
targetNamespace="http://www.skatestown.com/ns/po"
xmlnssd="http://www.w3.org/2001/XMLSchema">
<xsd:annotation>
<xsd:documentation xml:lang="en">
Purchase order schema for SkatesTown.
</xsd:documentation>
</xsd:annotation>
<xsd:element name="po" type="poType" />
<xsd:complexType name="poType">
<xsd:sequence>
<xsd:element name="billTo" type="addressType" />
<xsd:element name="shipTo" type="addressType" />
<xsd:element name="order">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="item" type="itemType" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" use="required" type="xsdositiveInteger" />
<xsd:attribute name="submitted" use="required" type="xsd:date" />
<xsd:attribute name="customerId" use="required" type="xsdositiveInteger"
/>
</xsd:complexType>
<xsd:complexType name="addressType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string" minOccurs="0" />
<xsd:element name="company" type="xsd:string" minOccurs="0" />
<xsd:element name="street" type="xsd:string" maxOccurs="unbounded" />
<xsd:element name="city" type="xsd:string" />
<xsd:element name="state" type="xsd:string" minOccurs="0" />
<xsd:element name="postalCode" type="xsd:string" minOccurs="0" />
<xsd:element name="country" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" />
<xsd:attribute name="href" type="xsd:IDREF" />
</xsd:complexType>
<xsd:complexType name="itemType">
<xsd:sequence>
<xsd:element name="description" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="sku" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsdattern value="\d{3}-[A-Z]{2}" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="quantity" use="required" type="xsdositiveInteger"
/>
</xsd:complexType>
</xsd:schema>


 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-02-2007
geoff wrote:
> This is how the book has the files (3 of them) but xml notepad says shipTo
> has to be filled out, I hate it when book examples do not work
>
>
> ======== INVOICE.XML ==========
>
> <?xml version="1.0" encoding="UTF-8"?>
> <invoice:invoice xmlns:invoice="http://www.skatestown.com/ns/invoice"
> xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.skatestown.com/ns/invoice
> ./invoice.xsd"
> id="43871" submitted="2004-01-05" customerId="73852">
> <billTo id="addr-1">
> <company>The Skateboard Warehouse</company>
> <street>One Warehouse Park</street>
> <street>Building 17</street>
> <city>Boston</city>
> <state>MA</state>
> <postalCode>01775</postalCode>
> </billTo>
> <shipTo href="addr-1"/>



shipTo is defined here

> <xsd:complexType name="invoiceType">
> <xsd:sequence>
> <xsd:element name="billTo" type="po:addressType" />
> <xsd:element name="shipTo" type="po:addressType" />

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
as being of type po:addressType and that is defined here

> <xsd:complexType name="addressType">
> <xsd:sequence>
> <xsd:element name="name" type="xsd:string" minOccurs="0" />
> <xsd:element name="company" type="xsd:string" minOccurs="0" />
> <xsd:element name="street" type="xsd:string" maxOccurs="unbounded" />
> <xsd:element name="city" type="xsd:string" />
> <xsd:element name="state" type="xsd:string" minOccurs="0" />
> <xsd:element name="postalCode" type="xsd:string" minOccurs="0" />
> <xsd:element name="country" type="xsd:string" minOccurs="0" />
> </xsd:sequence>
> <xsd:attribute name="id" type="xsd:ID" />
> <xsd:attribute name="href" type="xsd:IDREF" />
> </xsd:complexType>


It has mandatory child elements like street and city.

As said in my reply to your first post, IDREF does not mean that the
referenced element is included.


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
geoff
Guest
Posts: n/a
 
      12-02-2007
Got it.

The point of the book is that usually the shipTo and billTo addresses are
the same and it used the IDREF mechanism to prevent having to enter
duplicate information.

So, what mechanism would one use so addressType information is entered once?

--g


 
Reply With Quote
 
geoff
Guest
Posts: n/a
 
      12-02-2007
I found this in google, the same example as the book but apparently wrong,
grrrrrrrrrrr:

http://87.249.105.167/mirror/buildin...tml#ch02list03

--g


 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      12-02-2007
geoff wrote:

> So, what mechanism would one use so addressType information is entered once?


You could define a list of addresses, each with an ID, and then you
could have shipTo and billTo reference the ID value using an IDREF
attribute, as I have already tried to suggest e.g.
<invoice>
<address-list>
<address id="addr1">
...
</address>
</address-list>
<shipTo ref="addr1"/>
<billTo ref="addr1"/>
</invoice>


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
geoff
Guest
Posts: n/a
 
      12-03-2007
I guess it points out the importance of tools. I modified it by hand but
always got some schema declaration error.

I'll put it on the shelf for now and look for a tool to manipulate the xml
and schemas.

--g


 
Reply With Quote
 
geoff
Guest
Posts: n/a
 
      12-03-2007
Hello,

For my own benefit, I did what you suggested, using the po.xsd and po.xml
(did not use the invoice.xsd). In the xsd, I specified two choices, have
three address parts (addressList, shipTo, and billTo) where the use of 'id'
and 'href' are required or have two address parts, shipTo and billTo.

I am sure in real life it would be handled more efficiently but, hey, this
is an exercise

--g


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
idref, key and xmllint maxwell@ldc.upenn.edu XML 2 03-15-2007 01:59 PM
xml data binder with IDREF and substition group support? Elhanan Java 0 08-22-2006 05:21 PM
querry on ID's and IDREF in DTD Maulik Thaker XML 10 02-25-2006 05:19 PM
JAXB and IdRef kevkev Java 3 05-19-2005 04:56 PM
[semi-OT] java objects persistence and XML id/idref rico Java 2 10-28-2003 02:12 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57