ID and IDREF

Discussion in 'XML' started by geoff, Dec 2, 2007.

  1. geoff

    geoff Guest

    Hello,

    Why does this not work:

    <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"/>

    .. . . billTo and shipTo are defined as the same in the schema and I included
    the following in the schema definition:

    <xsd:attribute name="id" type="xsd:ID"/>
    <xsd:attribute name="href" type="xsd:IDREF"/>

    .. . . however, xml notepad says, 'the element shipTo has incomplete
    contents'. If I populate shipTo with the same info as billTo, it works fine
    but the referencing of billTo does not seem to work or is it a limitation of
    xml notepad?

    Thanks.

    --g
     
    geoff, Dec 2, 2007
    #1
    1. Advertising

  2. geoff wrote:

    > Why does this not work:
    >
    > <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"/>
    >
    > . . . billTo and shipTo are defined as the same in the schema and I included
    > the following in the schema definition:
    >
    > <xsd:attribute name="id" type="xsd:ID"/>
    > <xsd:attribute name="href" type="xsd:IDREF"/>
    >
    > . . . however, xml notepad says, 'the element shipTo has incomplete
    > contents'. If I populate shipTo with the same info as billTo, it works fine
    > but the referencing of billTo does not seem to work or is it a limitation of
    > xml notepad?


    If the schema for shipTo defines child elements then you have to include
    those child elements literally. There is no way to include them using a
    link mechanism, that is not how XSD schemas work.
    All ID/IDREF allow you is to refer to other components for instance
    <address id="addr1">
    <company>The Skateboard Warehouse</company>
    <street>One Warehouse Park</street>
    <street>Building 17</street>
    <city>Boston</city>
    <state>MA</state>
    <postalCode>01775</postalCode>
    </address>

    <billTo href="addr1"/>
    <shipTo href="addr1"/>
    but then the schema would not define child elements for billTo and
    shipTo, it would just define the attribute and its type.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 2, 2007
    #2
    1. Advertising

  3. geoff

    geoff Guest

    Interesting, here is the po.xsd (this is included in the invoiceschema.xsd
    which is used by po.xml, I put them in separate messages):

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

    <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="xsd:positiveInteger"/>
    <xsd:attribute name="submitted" use="required"
    type="xsd:date"/>
    <xsd:attribute name="customerId" use="required"
    type="xsd:positiveInteger"/>
    </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">
    <xsd:pattern value="\d{3}-[A-Z]{2}"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:attribute>
    <xsd:attribute name="quantity" use="required"
    type="xsd:positiveInteger"/>
    </xsd:complexType>

    </xsd:schema>


    "Martin Honnen" <> wrote in message
    news:4752b347$0$4371$-online.net...
    > geoff wrote:
    >
    >> Why does this not work:
    >>
    >> <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"/>
    >>
    >> . . . billTo and shipTo are defined as the same in the schema and I
    >> included the following in the schema definition:
    >>
    >> <xsd:attribute name="id" type="xsd:ID"/>
    >> <xsd:attribute name="href" type="xsd:IDREF"/>
    >>
    >> . . . however, xml notepad says, 'the element shipTo has incomplete
    >> contents'. If I populate shipTo with the same info as billTo, it works
    >> fine but the referencing of billTo does not seem to work or is it a
    >> limitation of xml notepad?

    >
    > If the schema for shipTo defines child elements then you have to include
    > those child elements literally. There is no way to include them using a
    > link mechanism, that is not how XSD schemas work.
    > All ID/IDREF allow you is to refer to other components for instance
    > <address id="addr1">
    > <company>The Skateboard Warehouse</company>
    > <street>One Warehouse Park</street>
    > <street>Building 17</street>
    > <city>Boston</city>
    > <state>MA</state>
    > <postalCode>01775</postalCode>
    > </address>
    >
    > <billTo href="addr1"/>
    > <shipTo href="addr1"/>
    > but then the schema would not define child elements for billTo and shipTo,
    > it would just define the attribute and its type.
    >
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
     
    geoff, Dec 2, 2007
    #3
  4. geoff

    geoff Guest

    This is invoiceschema.xsd which imports po.xsd

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

    <xsd:import namespace="http://www.skatestown.com/ns/po"
    schemaLocation="d:\temp\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" use="required"
    type="xsd:positiveInteger"/>
    <xsd:attribute name="submitted" use="required"
    type="xsd:date"/>
    <xsd:attribute name="customerId" use="required"
    type="xsd:positiveInteger"/>
    </xsd:complexType>

    <xsd:complexType name="itemType">
    <xsd:complexContent>
    <xsd:extension base="po:itemType">
    <xsd:attribute name="unitPrice" use="required"
    type="priceType"/>
    </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>
     
    geoff, Dec 2, 2007
    #4
  5. geoff

    geoff Guest

    This is invoice.xml which uses invoiceschema.xsd:

    <?xml version="1.0" encoding="UTF-8"?>
    <invoice:invoice xmlns:invoice="http://www.skatestown.com/ns/invoice"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.skatestown.com/ns/invoice
    d:\temp\invoiceschema.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>
     
    geoff, Dec 2, 2007
    #5
  6. geoff

    geoff Guest

    After I uploaded that, I can see it has some problems, oh well.

    --g
     
    geoff, Dec 2, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rico
    Replies:
    2
    Views:
    414
  2. kevkev

    JAXB and IdRef

    kevkev, May 18, 2005, in forum: Java
    Replies:
    3
    Views:
    4,335
    kevkev
    May 19, 2005
  3. Maulik Thaker

    querry on ID's and IDREF in DTD

    Maulik Thaker, Feb 21, 2006, in forum: XML
    Replies:
    10
    Views:
    1,250
    Aalap
    Feb 25, 2006
  4. Elhanan
    Replies:
    0
    Views:
    378
    Elhanan
    Aug 22, 2006
  5. Replies:
    2
    Views:
    1,379
Loading...

Share This Page