External Data and XML

An external data source, even one written using XML, can have a different XML document structure than you may want your XML document to have. When dealing with external data and XML, something like SOAP can be used to interpret the context and contents of an XML document. How can this be achieved? This is where SOAP messages and WSDL structural imposition onto those SOAP messages, come into play. The result is XML implemented across a heterogeneous environment. Obviously there are plenty of companies that use databases other than Oracle and SQL Server. Many of these databases do not have easy-to-use XML data types. So, SOAP and WSDL apply when not using Oracle or SQL server.

Essentially , WSDL uses XML Schema Definition (XSD) schema scripts in order to apply schema (relational table) structures onto SOAP message XML documents. In Chapter 6, you saw an example of using XSD scripting to store schemas, and what can even be called namespace collections, into a SQL Server database.

A heterogeneous environment is where two servers are essentially producing data that cannot be simply pushed in and out of two databases, using something like XML data types. There has to be some kind of transformation of XML data between the two HTTP end points. One method of solving the transformation issue is through the use of SOAP messages and WSDL XSD schemas. SOAP is covered in this chapter and XSD schemas are covered in Chapter 6.

B2B Data Transfer

Business-2-Business, or B2B data transfers, can utilize XML data and XSL style sheets to transfer data between two disparate data sources, such as two completely different companies. XSL can be used to transform the XML data between the two data structural requirements of the two different companies.

Two companies, both having different XML document data structures, can pass the same XML data backwards and forwards. The data structure can be changed very easily simply by using a style sheet. Chapter 3 covers the use of XSL (eXtensible Style Sheets).

Using XSL to reformat XML data is probably the easiest method of transferring XML data across heterogeneous environments. This assumes that you can utilize XML documents at either end. However, even if both ends contain relational databases, with different table structures, there is no reason why XSL should not be used to perform an initial restructuring of XML dataprior to reinsertion into relational databases tables.

Figure 7-1 contains an XML document, wrapped up in a SOAP message. That XML document looks like this:

   <region name="Europe">    <country name="England">       <city>London</city>       <city>Manchester</city>    </country>    <country name="Germany">       <city>Hamburg</city>       <city>Frankfurt</city>    </country> </region>   

Now you can use something like this XSL style sheet to rearrange the structure of the XML data:

   <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">    <xsl:template match="/">       <HTML><BODY>          <xsl:for-each select="region">             &lt;<xsl:value-of select="name()"/>&gt;             &lt;name&gt;<xsl:value-of select="@name"/>&lt;/name&gt;             <xsl:for-each select="country">                &lt;<xsl:value-of select="name()"/>&gt;                &lt;name&gt;<xsl:value-of select="@name"/>&lt;/name&gt;                <xsl:for-each select="city">                   &lt;<xsl:value-of select="name()"/>&gt;                   <xsl:value-of select="text()"/>                   &lt;/<xsl:value-of select="name()"/>&gt;                </xsl:for-each>                &lt;/<xsl:value-of select="name()"/>&gt;             </xsl:for-each>             &lt;/<xsl:value-of select="name()"/>&gt;          </xsl:for-each>       </BODY></HTML>    </xsl:template> </xsl:stylesheet>   

There are better methods of resolving the preceding transformation using templates but this seemed like a good way to explain it in a programmatic, rather than a declarative, fashion. The result of the transformation looks like this:

   <region>    <name>Europe</name>    <country>       <name>England</name>       <city>London</city>       <city>Manchester</city>    </country>    <country>       <name>Germany</name>       <city>Hamburg</city>       <city>Frankfurt</city>    </country> </region>   

As opposed to the structure shown in Figure 7-1, the output of the transformed XML data looks like that shown in Figure 7-8.

image from book
Figure 7-8: Transferring data using XSL transformations

This chapter has covered the use of XML in heterogeneous environments. A heterogeneous environment is one in which there is more than one database, quite often more than two databases. Additionally, there might be multiple operating systems and various different hardware platforms. It is essential to have some method of passing messages between the various environments. SOAP can help to accomplish this by wrapping XML documents into specialized XML wrappers. SOAP XML wrapper elements are as universally understood as XML is itself.



Beginning XML Databases
Beginning XML Databases (Wrox Beginning Guides)
ISBN: 0471791202
EAN: 2147483647
Year: 2006
Pages: 183
Authors: Gavin Powell

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net