OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

xdi message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: Some XDI examples (including enveloped)


Attached are some annotated XDI examples that might be useful for
tomorrow's call.

Dave

Example 1 - Original XML

This is the XML document used as an example by the XML Schema Primer.

<purchaseOrder orderDate="1999-10-20">
    <shipTo country="US">
        <name>Alice Smith</name>
        <street>123 Maple Street</street>
        <city>Mill Valley</city>
        <state>CA</state>
        <zip>90952</zip>
    </shipTo>
    <billTo country="US">
        <name>Robert Smith</name>
        <street>8 Oak Avenue</street>
        <city>Old Town</city>
        <state>PA</state>
        <zip>95819</zip>
    </billTo>
    <comment>Hurry, my lawn is going wild!</comment>
    <items>
        <item partNum="872-AA">
            <productName>Lawnmower</productName>
            <quantity>1</quantity>
            <USPrice>148.95</USPrice>
            <comment>Confirm this is electric</comment>
        </item>
        <item partNum="926-AA">
            <productName>Baby Monitor</productName>
            <quantity>1</quantity>
            <USPrice>39.98</USPrice>
            <shipDate>1999-05-21</shipDate>
        </item>
    </items>
</purchaseOrder>

Example 2 - All data

If we want it all to be data, it's easy.

<resource>
    <xri>@:1001:1:2</xri>
    <data>
        <purchaseOrder orderDate="1999-10-20">
            <shipTo country="US">
                <name>Alice Smith</name>
                <street>123 Maple Street</street>
                <city>Mill Valley</city>
                <state>CA</state>
                <zip>90952</zip>
            </shipTo>
            <billTo country="US">
                <name>Robert Smith</name>
                <street>8 Oak Avenue</street>
                <city>Old Town</city>
                <state>PA</state>
                <zip>95819</zip>
            </billTo>
            <comment>Hurry, my lawn is going wild!</comment>
            <items>
                <item partNum="872-AA">
                    <productName>Lawnmower</productName>
                    <quantity>1</quantity>
                    <USPrice>148.95</USPrice>
                    <comment>Confirm this is electric</comment>
                </item>
                <item partNum="926-AA">
                    <productName>Baby Monitor</productName>
                    <quantity>1</quantity>
                    <USPrice>39.98</USPrice>
                    <shipDate>1999-05-21</shipDate>
                </item>
            </items>
        </purchaseOrder>
    </data>
</resource>

Example 3 - All XDI

If we want it be marked up with XDI using an enveloping model, we lose the XML-ness. This is just a pure, straight transformation. It doesn't do much good by itself, but it gives us a base to work from.

Notice that when we follow the XML, we break the proposed rule about name uniqueness on "item". In other words, @:1001:1:2/purchaseOrder/items/item doesn't return a single node, it returns a node set, just like XPath. The only issue is that the result of an XDI request may not be well formed XML since it may have multiple root nodes, so we probably need to wrap all responses in a containing resource element.

<resource>
    <xri>@:1001:1:2</xri>
    <resource>
        <xri>purchaseOrder</xri>
        <resource>
            <xri>orderDate</xri>
            <data>1999-10-20</data>
        </resource>
        <resource>
            <xri>shipTo</xri>
            <resource>
                <xri>country</xri>
                <data>US</data>
            </resource>
            <resource>
                <xri>name</xri>
                <data>Alice Smith</data>
            </resource>
            <resource>
                <xri>street</xri>
                <data>123 Maple Street</data>
            </resource>
            <resource>
                <xri>city</xri>
                <data>Mill Valley</data>
            </resource>
            <resource>
                <xri>state</xri>
                <data>CA</data>
            </resource>
            <resource>
                <xri>zip</xri>
                <data>90952</data>
            </resource>
        </resource>
        <resource>
            <xri>billTo</xri>
            <resource>
                <xri>country</xri>
                <data>US</data>
            </resource>
            <resource>
                <xri>name</xri>
                <data>Robert Smith</data>
            </resource>
            <resource>
                <xri>street</xri>
                <data>8 Oak Avenue</data>
            </resource>
            <resource>
                <xri>city</xri>
                <data>Old Town</data>
            </resource>
            <resource>
                <xri>state</xri>
                <data>PA</data>
            </resource>
            <resource>
                <xri>zip</xri>
                <data>95819</data>
            </resource>
        </resource>
        <resource>
            <xri>comment</xri>
            <data>Hurry, my lawn is going wild!</data>
        <resource>
        <resource>
            <xri>items</xri>
            <resource>
                <xri>item</xri>
                    <resource>
                        <xri>partNum</xri>
                        <data>872-AA</data>
                    </resource>
                    <resource>
                        <xri>productName</xri>
                        <data>Lawnmower</data>
                    </resource>
                    <resource>
                        <xri>quantity</xri>
                        <data>1</data>
                    </resource>
                    <resource>
                        <xri>USPrice</xri>
                        <data>148.95</data>
                    </resource>
                    <resource>
                        <xri>comment</xri>
                        <data>Confirm this is electric</data>
                    </resource>
                </resource>
                <xri>item</xri>
                    <resource>
                        <xri>partNum</xri>
                        <data>926-AA</data>
                    </resource>
                    <resource>
                        <xri>productName</xri>
                        <data>Baby Monitor</data>
                    </resource>
                    <resource>
                        <xri>quantity</xri>
                        <data>1</data>
                    </resource>
                    <resource>
                        <xri>USPrice</xri>
                        <data>39.98</data>
                    </resource>
                    <resource>
                        <xri>shipDate</xri>
                        <data>1999-05-21</data>
                    </resource>
                </resource>
            </resource> 
        </resource> 
    </resource> 
</resource> 

Example 4 - All XDI with persistent addresses

Now we'll make this a little more useful by making the individual elements persistently addressable.

Now we have a way to distinguish between item nodes. We can say that @:1001:1:2/purchaseOrder/items/item returns both @:1001:1:2/purchaseOrder/items/:1 and @:1001:1:2/purchaseOrder/items/:2.

<resource>
    <xri>@:1001:1:2</xri>
    <resource>
        <xri>purchaseOrder</xri>
        <xri>:1</xri>
        <resource>
            <xri>orderDate</xri>
            <xri>:1</xri>
            <data>1999-10-20</data>
        </resource>
        <resource>
            <xri>shipTo</xri>
            <xri>:1</xri>
            <resource>
                <xri>country</xri>
                <xri>:1</xri>
                <data>US</data>
            </resource>
            <resource>
                <xri>name</xri>
                <xri>:2</xri>
                <data>Alice Smith</data>
            </resource>
            <resource>
                <xri>street</xri>
                <xri>:3</xri>
                <data>123 Maple Street</data>
            </resource>
            <resource>
                <xri>city</xri>
                <xri>:4</xri>
                <data>Mill Valley</data>
            </resource>
            <resource>
                <xri>state</xri>
                <xri>:5</xri>
                <data>CA</data>
            </resource>
            <resource>
                <xri>zip</xri>
                <xri>:6</xri>
                <data>90952</data>
            </resource>
        </resource>
        <resource>
            <xri>billTo</xri>
            <xri>:2</xri>
            <resource>
                <xri>country</xri>
                <xri>:1</xri>
                <data>US</data>
            </resource>
            <resource>
                <xri>name</xri>
                <xri>:2</xri>
                <data>Robert Smith</data>
            </resource>
            <resource>
                <xri>street</xri>
                <xri>:3</xri>
                <data>8 Oak Avenue</data>
            </resource>
            <resource>
                <xri>city</xri>
                <xri>:4</xri>
                <data>Old Town</data>
            </resource>
            <resource>
                <xri>state</xri>
                <xri>:5</xri>
                <data>PA</data>
            </resource>
            <resource>
                <xri>zip</xri>
                <xri>:6</xri>
                <data>95819</data>
            </resource>
        </resource>
        <resource>
            <xri>comment</xri>
            <xri>:3</xri>
            <data>Hurry, my lawn is going wild!</data>
        <resource>
        <resource>
            <xri>items</xri>
            <xri>:4</xri>
            <resource>
                <xri>item</xri>
                <xri>:1</xri>
                <resource>
                    <xri>partNum</xri>
                    <xri>:1</xri>
                    <data>872-AA</data>
                </resource>
                <resource>
                    <xri>productName</xri>
                    <xri>:2</xri>
                    <data>Lawnmower</data>
                </resource>
                <resource>
                    <xri>quantity</xri>
                    <xri>:3</xri>
                    <data>1</data>
                </resource>
                <resource>
                    <xri>USPrice</xri>
                    <xri>:4</xri>
                    <data>148.95</data>
                </resource>
                <resource>
                    <xri>comment</xri>
                    <xri>:5</xri>
                    <data>Confirm this is electric</data>
                </resource>
            </resource>
            <resource>
                <xri>item</xri>
                <xri>:2</xri>
                <resource>
                    <xri>partNum</xri>
                    <xri>:1</xri>
                    <data>926-AA</data>
                </resource>
                <resource>
                    <xri>productName</xri>
                    <xri>:2</xri>
                    <data>Baby Monitor</data>
                </resource>
                <resource>
                    <xri>quantity</xri>
                    <xri>:3</xri>
                    <data>1</data>
                </resource>
                <resource>
                    <xri>USPrice</xri>
                    <xri>:4</xri>
                    <data>39.98</data>
                </resource>
                <resource>
                    <xri>shipDate</xri>
                    <xri>:5</xri>
                    <data>1999-05-21</data>
                </resource>
            </resource>
        </resource> 
    </resource> 
</resource> 

Example 5 - Mixed XDI and XML

Once we hit a <data> element, we drop out of XDI. It's appropriate to do this when we no longer care about associating XRI addresses or other metadata with a node. Here we'll represent address and item data as XML, which will make the previous example a little more manageable.

<resource>
    <xri>@:1001:1:2</xri>
    <resource>
        <xri>purchaseOrder</xri>
        <xri>:1</xri>
        <resource>
            <xri>orderDate</xri>
            <xri>:1</xri>
            <data>1999-10-20</data>
        </resource>
        <resource>
            <xri>shipTo</xri>
            <xri>:1</xri>
            <resource>
                <xri>country</xri>
                <xri>:1</xri>
                <data>US</data>
            </resource>
            <data>
                <name>Alice Smith</name>
                <street>123 Maple Street</street>
                <city>Mill Valley</city>
                <state>CA</state>
                <zip>90952</zip>
            </data> 
        </resource>
        <resource>
            <xri>billTo</xri>
            <xri>:2</xri>
            <resource>
                <xri>country</xri>
                <xri>:1</xri>
                <data>US</data>
            </resource>
            <data>
                <name>Robert Smith</name>
                <street>8 Oak Avenue</street>
                <city>Old Town</city>
                <state>PA</state>
                <zip>95819</zip>
            </data>
        </resource>
        <resource>
            <xri>comment</xri>
            <xri>:3</xri>
            <data>Hurry, my lawn is going wild!</data>
        <resource>
        <resource>
            <xri>items</xri>
            <xri>:4</xri>
            <resource>
                <xri>item</xri>
                <xri>:1</xri>
                <resource>
                    <xri>partNum</xri>
                    <xri>:1</xri>
                    <data>872-AA</data>
                </resource>
                <data>
                    <productName>Lawnmower</productName>
                    <quantity>1</quantity>
                    <USPrice>148.95</USPrice>
                    <comment>Confirm this is electric</comment>
                </data>
            </resource>
            <resource>
                <xri>item</xri>
                <xri>:2</xri>
                <resource>
                    <xri>partNum</xri>
                    <xri>:1</xri>
                    <data>926-AA</data>
                </resource>
                <data>
                    <productName>Baby Monitor</productName>
                    <quantity>1</quantity>
                    <USPrice>39.98</USPrice>
                    <shipDate>1999-05-21</shipDate>
                </data>
            </resource>
        </resource> 
    </resource> 
</resource> 

Example 6 - Basic enveloped 

Now we'll give a few persistent identifiers (like example 5) using an enveloped model. This is appropriate for extensible schemas where the XML consumer may not be XDI aware.

Notice the xdi:reference element. This is very similar to a reference element ini XML Digital Signatures. Notice also that the examples show two different methods for filtering the referenced XML - an algorithm defined by the TC called xri:@oasis*xdi/enveloped-resource and an XPath expression. The XPath expression in this example is actually equivalent to the enveloped-resource transform, so the two are interchangeable. In other words,

<xdi:transform algorithm="xri:@oasis*xdi/enveloped-resource" />

is defined as

<xdi:transform
  algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116";>
    <xdi:xpath xmlns:dsig="&xdi;">
    count(ancestor-or-self::xdi:resource |
    here()/ancestor::xdi:resource[1]) >
    count(ancestor-or-self::xdi:resource)</
    </xdi:xpath>
</xdi:transform>

The XPointer syntax may not be exactly correct, by the way, but it should be easy enough to tell what I mean.

<purchaseOrder orderDate="1999-10-20" id="PO">
    <shipTo country="US">
        <name>Alice Smith</name>
        <street>123 Maple Street</street>
        <city>Mill Valley</city>
        <state>CA</state>
        <zip>90952</zip>
        <xdi:resource xmlns:xdi="xri:@oasis*xdi">
            <xdi:xri>:1</xdi:xri>
            <xdi:reference URI="#xpointer(id(&apos;PO&apos;))/child::shipTo">
                <xdi:transform
                  algorithm="xri:@oasis*xdi/enveloped-resource" />
            <xdi:reference>
        </xdi:resource>
    </shipTo>
    <billTo country="US">
        <name>Robert Smith</name>
        <street>8 Oak Avenue</street>
        <city>Old Town</city>
        <state>PA</state>
        <zip>95819</zip>
        <xdi:resource xmlns:xdi="xri:@oasis*xdi">
            <xdi:xri>:2</xdi:xri>
            <xdi:reference URI="#xpointer(id(&apos;PO&apos;))/child::billTo">
                <xdi:transform
                  algorithm="xri:@oasis*xdi/enveloped-resource" />
            <xdi:reference>
        </xdi:resource>
    </billTo>
    <comment>Hurry, my lawn is going wild!</comment>
    <items>
        <item partNum="872-AA">
            <productName>Lawnmower</productName>
            <quantity>1</quantity>
            <USPrice>148.95</USPrice>
            <comment>Confirm this is electric</comment>
        </item>
        <item partNum="926-AA">
            <productName>Baby Monitor</productName>
            <quantity>1</quantity>
            <USPrice>39.98</USPrice>
            <shipDate>1999-05-21</shipDate>
        </item>
        <resource xmlns:xlink="http://www.w3.org/1999/xlink";>
            <xri>:4</xri>
            <xdi:reference URI="#xpointer(id(&apos;PO&apos;))/child::items">
                <xdi:transform
                  algorithm="xri:@oasis*xdi/enveloped-resource" />
            <xdi:reference>
        </resource>
    </items>
    <xdi:resource xmlns:xdi="xri:@oasis*xdi">
        <xdi:xri>@:1001:1:2</xdi:xri>
        <xdi:reference URI="#PO">
            <xdi:transform
              algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116";>
                <xdi:xpath xmlns:xdi="&xdi;">
                count(ancestor-or-self::xdi:resource |
                here()/ancestor::xdi:resource[1]) >
                count(ancestor-or-self::xdi:resource)</xdi:xpath>
            </xdi:transform>
        <xdi:reference>
    </xdi:resource>
</purchaseOrder>

Example 7 - Enveloped fragment breaks refs

Notice that the references are all in terms of #PO. This is probably a poor practice because they become meaningless if a chunk of the XML above is put into a different context. For example, if we put the shipTo portion in its own document, we have

<shipTo country="US">
    <name>Alice Smith</name>
    <street>123 Maple Street</street>
    <city>Mill Valley</city>
    <state>CA</state>
    <zip>90952</zip>
    <xdi:resource xmlns:xdi="xri:@oasis*xdi">
        <xdi:xri>:1</xdi:xri>
        <xdi:reference URI="#xpointer(id(&apos;PO&apos;))/child::shipTo">
            <xdi:transform
              algorithm="xri:@oasis*xdi/enveloped-resource" />
        <xdi:reference>
    </xdi:resource>
</shipTo> 

The reference URI depended on the original context and is now broken. If we're using the enveloping form of XDI, we can reasonably impose processing rules when the XDI document is broken up. With enveloped, however, we can't assume the processor is even aware of XDI. Best practice would suggest that we make references context independent. Because I'm terrible at XPointer syntax, I'm going to cheat and pretend there was an ID attribute on the shipTo element.

<shipTo country="US" id="shipTo">
    <name>Alice Smith</name>
    <street>123 Maple Street</street>
    <city>Mill Valley</city>
    <state>CA</state>
    <zip>90952</zip>
    <xdi:resource xmlns:xdi="xri:@oasis*xdi">
        <xdi:xri>:1</xdi:xri>
        <xdi:reference URI="#shipTo">
            <xdi:transform
              algorithm="xri:@oasis*xdi/enveloped-resource" />
        <xdi:reference>
    </xdi:resource>
</shipTo>


Example 8 - Enveloped fragment breaks relative XRIs

For the same reason we made references context independent, we should also make XRIs context independent. The relative XRI above (:1), is meaningless now that the shipTo portion stands alone. A better practice would be to make XRIs absolute. Example 6, then, is better expressed as follows (again with the ID cheat to make the XPointers simple and with the simplified transform expression).

<purchaseOrder orderDate="1999-10-20" id="PO">
    <shipTo country="US" id="shipTo">
        <name>Alice Smith</name>
        <street>123 Maple Street</street>
        <city>Mill Valley</city>
        <state>CA</state>
        <zip>90952</zip>
        <xdi:resource xmlns:xdi="xri:@oasis*xdi">
            <xdi:xri>@:1001:1:2/:1</xdi:xri>
            <xdi:reference URI="#shipTo">
                <xdi:transform
                  algorithm="xri:@oasis*xdi/enveloped-resource" />
            <xdi:reference>
        </xdi:resource>
    </shipTo>
    <billTo country="US" id="billTo">
        <name>Robert Smith</name>
        <street>8 Oak Avenue</street>
        <city>Old Town</city>
        <state>PA</state>
        <zip>95819</zip>
        <xdi:resource xmlns:xdi="xri:@oasis*xdi">
            <xdi:xri>@:1001:1:2/:2</xdi:xri>
            <xdi:reference URI="#billTo">
                <xdi:transform
                  algorithm="xri:@oasis*xdi/enveloped-resource" />
            <xdi:reference>
        </xdi:resource>
    </billTo>
    <comment>Hurry, my lawn is going wild!</comment>
    <items id="items">
        <item partNum="872-AA">
            <productName>Lawnmower</productName>
            <quantity>1</quantity>
            <USPrice>148.95</USPrice>
            <comment>Confirm this is electric</comment>
        </item>
        <item partNum="926-AA">
            <productName>Baby Monitor</productName>
            <quantity>1</quantity>
            <USPrice>39.98</USPrice>
            <shipDate>1999-05-21</shipDate>
        </item>
        <resource xmlns:xlink="http://www.w3.org/1999/xlink";>
            <xri>@:1001:1:2/:4</xri>
            <xdi:reference URI="#items">
                <xdi:transform
                  algorithm="xri:@oasis*xdi/enveloped-resource" />
            <xdi:reference>
        </resource>
    </items>
    <xdi:resource xmlns:xdi="xri:@oasis*xdi">
        <xdi:xri>@:1001:1:2</xdi:xri>
        <xdi:reference URI="#PO">
            <xdi:transform
              algorithm="xri:@oasis*xdi/enveloped-resource" />
        <xdi:reference>
    </xdi:resource>
</purchaseOrder>


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]