You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Shelli D. Orton" <sh...@wmode.com> on 2006/01/13 01:51:26 UTC

Question about importing XSD files

Hi All,

My practical problem is this: I have been given a wsdl file and 2 xsd files
to generate a client app against.  The wsdl does not import the xsd files,
so I'm trying to fix it so that it does and I can run wsdl2java against it.
So, I am trying to understand how to import schema files (.xsd) into a wsdl
document.  I have found two examples on how to do this (actually more, but
these were fairly clean examples).  

The example from the w3 (http://www.w3.org/TR/wsdl) site is:

<?xml version="1.0"?>
<definitions name="StockQuote"

targetNamespace="http://example.com/stockquote/definitions"
          xmlns:tns="http://example.com/stockquote/definitions"
          xmlns:xsd1="http://example.com/stockquote/schemas"
          xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
          xmlns="http://schemas.xmlsoap.org/wsdl/">

   <import namespace="http://example.com/stockquote/schemas"
           location="http://example.com/stockquote/stockquote.xsd"/>

    <message name="GetLastTradePriceInput">
        <part name="body" element="xsd1:TradePriceRequest"/>
    </message>

    <message name="GetLastTradePriceOutput">
        <part name="body" element="xsd1:TradePrice"/>
    </message>

    <portType name="StockQuotePortType">
        <operation name="GetLastTradePrice">
           <input message="tns:GetLastTradePriceInput"/>
           <output message="tns:GetLastTradePriceOutput"/>
        </operation>
    </portType>
</definitions>

Another example I found is (from
http://www-128.ibm.com/developerworks/xml/library/ws-tip-imports.html):

<wsdl:types>
    <xsd:schema targetNamespace="urn:listing2"
                xmlns:listing3="urn:listing3"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema">

      <xsd:import namespace="urn:listing3" schemaLocation="listing3.xsd"/>

      <xsd:import namespace="http://www.w3.org/2001/XMLSchema"/>
      <xsd:complexType name="Address">
        <xsd:sequence>
          <xsd:element name="streetNum" type="xsd:int"/>
          <xsd:element name="streetName" type="xsd:string"/>
          <xsd:element name="city" type="xsd:string"/>
          <xsd:element name="state" type="xsd:string"/>
          <xsd:element name="phone" type="listing3:Phone"/>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>
  </wsdl:types>

In the first example, the xsd file is being imported in the definition
section, and I'm assuming is available throughout the rest of the wsdl after
that.  In the second, the xsd is being imported in a schema within the types
section and is therefore only available in that schema.  Is this correct?

I don't understand the significance/difference between the first example
using "location" and the second using "schemaLocation".  I also don't
understand how to reference the file's location.  Does it have to be made
available on the internet as example 1 suggests, or is the xsd files
co-located with wsdl good enough?

Any help is greatly appreciated.

Shelli



RE: Question about importing XSD files

Posted by "Shelli D. Orton" <sh...@wmode.com>.
Thanks Dies and Anne.  Things are much clearer now, and I think I can move
forward now.

Shelli
  -----Original Message-----
  From: Anne Thomas Manes [mailto:atmanes@gmail.com]
  Sent: Friday, January 13, 2006 7:47 AM
  To: axis-user@ws.apache.org
  Subject: Re: Question about importing XSD files


  Dies is correct. The first example is invalid. You should follow the
second example.

  In answer to your specific questions:


  In the first example, the xsd file is being imported in the definition
  section, and I'm assuming is available throughout the rest of the wsdl
after
  that.  In the second, the xsd is being imported in a schema within the
types
  section and is therefore only available in that schema.  Is this correct?


  This example is incorrect because it uses <wsdl:import> to import an xsd
file. You must use <xsd:import> to import a schema. As long as the xsd file
is imported into a schema in the types section, you can reference the schema
entities (elements, attributes, and types) throughout the WSDL.


  I don't understand the significance/difference between the first example
  using "location" and the second using "schemaLocation".  I also don't
  understand how to reference the file's location.  Does it have to be made
  available on the internet as example 1 suggests, or is the xsd files
  co-located with wsdl good enough?

  <wsdl:import> and <xsd:import> are different elements. The location
attribute in <wsdl:import> is "location". The location attribute in
<xsd:import> is "schemaLocation". The URI specified in either location
attribute can be an absolute or relative URL.

  Anne



  On 1/12/06, Dies Koper <di...@jp.fujitsu.com> wrote:
    Hello Shelli,

    The first example looks like the ones in the WSDL1.1 spec.
    However, according to the WS-I spec it is wrong.
    It says that you should not use wsdl:import to import xsd files. Use
    wsdl:import to import wsdl files, xsd:import to import xsd files.
    The second example seems to correct this.

    I think both would work fine with Axis. To prevent problems in the
    future, I'd go with the second example.

    The file location is a URI. A URL is fine, but a relative path to the
    file is fine too.

    Regards,
    Dies


    Shelli D. Orton wrote:
    > Hi All,
    >
    > My practical problem is this: I have been given a wsdl file and 2 xsd
files
    > to generate a client app against.  The wsdl does not import the xsd
files,
    > so I'm trying to fix it so that it does and I can run wsdl2java
against it.
    > So, I am trying to understand how to import schema files (.xsd) into a
wsdl
    > document.  I have found two examples on how to do this (actually more,
but
    > these were fairly clean examples).
    >
    > The example from the w3 (http://www.w3.org/TR/wsdl) site is:
    >
    > <?xml version="1.0"?>
    > <definitions name="StockQuote"
    >
    > targetNamespace="http://example.com/stockquote/definitions"
    >           xmlns:tns=" http://example.com/stockquote/definitions"
    >           xmlns:xsd1="http://example.com/stockquote/schemas"
    >           xmlns:soap=" http://schemas.xmlsoap.org/wsdl/soap/"
    >           xmlns="http://schemas.xmlsoap.org/wsdl/">
    >
    >    <import namespace=" http://example.com/stockquote/schemas"
    >            location="http://example.com/stockquote/stockquote.xsd"/>
    >
    >     <message name="GetLastTradePriceInput">
    >         <part name="body" element="xsd1:TradePriceRequest"/>
    >     </message>
    >
    >     <message name="GetLastTradePriceOutput">
    >         <part name="body" element="xsd1:TradePrice"/>
    >     </message>
    >
    >     <portType name="StockQuotePortType">
    >         <operation name="GetLastTradePrice">
    >            <input message="tns:GetLastTradePriceInput"/>
    >            <output message="tns:GetLastTradePriceOutput"/>
    >         </operation>
    >     </portType>
    > </definitions>
    >
    > Another example I found is (from
    >
http://www-128.ibm.com/developerworks/xml/library/ws-tip-imports.html):
    >
    > <wsdl:types>
    >     <xsd:schema targetNamespace="urn:listing2"
    >                 xmlns:listing3="urn:listing3"
    >                 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    >
    >       <xsd:import namespace="urn:listing3"
schemaLocation="listing3.xsd"/>
    >
    >       <xsd:import namespace="http://www.w3.org/2001/XMLSchema"/>
    >       <xsd:complexType name="Address">
    >         <xsd:sequence>
    >           <xsd:element name="streetNum" type="xsd:int"/>
    >           <xsd:element name="streetName" type="xsd:string"/>
    >           <xsd:element name="city" type="xsd:string"/>
    >           <xsd:element name="state" type="xsd:string"/>
    >           <xsd:element name="phone" type="listing3:Phone"/>
    >         </xsd:sequence>
    >       </xsd:complexType>
    >     </xsd:schema>
    >   </wsdl:types>
    >
    > In the first example, the xsd file is being imported in the definition
    > section, and I'm assuming is available throughout the rest of the wsdl
after
    > that.  In the second, the xsd is being imported in a schema within the
types
    > section and is therefore only available in that schema.  Is this
correct?
    >
    > I don't understand the significance/difference between the first
example
    > using "location" and the second using "schemaLocation".  I also don't
    > understand how to reference the file's location.  Does it have to be
made
    > available on the internet as example 1 suggests, or is the xsd files
    > co-located with wsdl good enough?
    >
    > Any help is greatly appreciated.
    >
    > Shelli
    >
    >




Re: Question about importing XSD files

Posted by Anne Thomas Manes <at...@gmail.com>.
Dies is correct. The first example is invalid. You should follow the second
example.

In answer to your specific questions:

In the first example, the xsd file is being imported in the definition
section, and I'm assuming is available throughout the rest of the wsdl after
that.  In the second, the xsd is being imported in a schema within the types
section and is therefore only available in that schema.  Is this correct?

 This example is incorrect because it uses <wsdl:import> to import an xsd
file. You must use <xsd:import> to import a schema. As long as the xsd file
is imported into a schema in the types section, you can reference the schema
entities (elements, attributes, and types) throughout the WSDL.

I don't understand the significance/difference between the first example
using "location" and the second using "schemaLocation".  I also don't
understand how to reference the file's location.  Does it have to be made
available on the internet as example 1 suggests, or is the xsd files
co-located with wsdl good enough?

<wsdl:import> and <xsd:import> are different elements. The location
attribute in <wsdl:import> is "location". The location attribute in
<xsd:import> is "schemaLocation". The URI specified in either location
attribute can be an absolute or relative URL.

Anne


On 1/12/06, Dies Koper <di...@jp.fujitsu.com> wrote:
>
> Hello Shelli,
>
> The first example looks like the ones in the WSDL1.1 spec.
> However, according to the WS-I spec it is wrong.
> It says that you should not use wsdl:import to import xsd files. Use
> wsdl:import to import wsdl files, xsd:import to import xsd files.
> The second example seems to correct this.
>
> I think both would work fine with Axis. To prevent problems in the
> future, I'd go with the second example.
>
> The file location is a URI. A URL is fine, but a relative path to the
> file is fine too.
>
> Regards,
> Dies
>
>
> Shelli D. Orton wrote:
> > Hi All,
> >
> > My practical problem is this: I have been given a wsdl file and 2 xsd
> files
> > to generate a client app against.  The wsdl does not import the xsd
> files,
> > so I'm trying to fix it so that it does and I can run wsdl2java against
> it.
> > So, I am trying to understand how to import schema files (.xsd) into a
> wsdl
> > document.  I have found two examples on how to do this (actually more,
> but
> > these were fairly clean examples).
> >
> > The example from the w3 (http://www.w3.org/TR/wsdl) site is:
> >
> > <?xml version="1.0"?>
> > <definitions name="StockQuote"
> >
> > targetNamespace="http://example.com/stockquote/definitions"
> >           xmlns:tns="http://example.com/stockquote/definitions"
> >           xmlns:xsd1="http://example.com/stockquote/schemas"
> >           xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
> >           xmlns="http://schemas.xmlsoap.org/wsdl/">
> >
> >    <import namespace="http://example.com/stockquote/schemas"
> >            location="http://example.com/stockquote/stockquote.xsd"/>
> >
> >     <message name="GetLastTradePriceInput">
> >         <part name="body" element="xsd1:TradePriceRequest"/>
> >     </message>
> >
> >     <message name="GetLastTradePriceOutput">
> >         <part name="body" element="xsd1:TradePrice"/>
> >     </message>
> >
> >     <portType name="StockQuotePortType">
> >         <operation name="GetLastTradePrice">
> >            <input message="tns:GetLastTradePriceInput"/>
> >            <output message="tns:GetLastTradePriceOutput"/>
> >         </operation>
> >     </portType>
> > </definitions>
> >
> > Another example I found is (from
> > http://www-128.ibm.com/developerworks/xml/library/ws-tip-imports.html):
> >
> > <wsdl:types>
> >     <xsd:schema targetNamespace="urn:listing2"
> >                 xmlns:listing3="urn:listing3"
> >                 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> >
> >       <xsd:import namespace="urn:listing3" schemaLocation="listing3.xsd
> "/>
> >
> >       <xsd:import namespace="http://www.w3.org/2001/XMLSchema"/>
> >       <xsd:complexType name="Address">
> >         <xsd:sequence>
> >           <xsd:element name="streetNum" type="xsd:int"/>
> >           <xsd:element name="streetName" type="xsd:string"/>
> >           <xsd:element name="city" type="xsd:string"/>
> >           <xsd:element name="state" type="xsd:string"/>
> >           <xsd:element name="phone" type="listing3:Phone"/>
> >         </xsd:sequence>
> >       </xsd:complexType>
> >     </xsd:schema>
> >   </wsdl:types>
> >
> > In the first example, the xsd file is being imported in the definition
> > section, and I'm assuming is available throughout the rest of the wsdl
> after
> > that.  In the second, the xsd is being imported in a schema within the
> types
> > section and is therefore only available in that schema.  Is this
> correct?
> >
> > I don't understand the significance/difference between the first example
> > using "location" and the second using "schemaLocation".  I also don't
> > understand how to reference the file's location.  Does it have to be
> made
> > available on the internet as example 1 suggests, or is the xsd files
> > co-located with wsdl good enough?
> >
> > Any help is greatly appreciated.
> >
> > Shelli
> >
> >
>
>

Re: Question about importing XSD files

Posted by Dies Koper <di...@jp.fujitsu.com>.
Hello Shelli,

The first example looks like the ones in the WSDL1.1 spec.
However, according to the WS-I spec it is wrong.
It says that you should not use wsdl:import to import xsd files. Use 
wsdl:import to import wsdl files, xsd:import to import xsd files.
The second example seems to correct this.

I think both would work fine with Axis. To prevent problems in the 
future, I'd go with the second example.

The file location is a URI. A URL is fine, but a relative path to the 
file is fine too.

Regards,
Dies


Shelli D. Orton wrote:
> Hi All,
> 
> My practical problem is this: I have been given a wsdl file and 2 xsd files
> to generate a client app against.  The wsdl does not import the xsd files,
> so I'm trying to fix it so that it does and I can run wsdl2java against it.
> So, I am trying to understand how to import schema files (.xsd) into a wsdl
> document.  I have found two examples on how to do this (actually more, but
> these were fairly clean examples).  
> 
> The example from the w3 (http://www.w3.org/TR/wsdl) site is:
> 
> <?xml version="1.0"?>
> <definitions name="StockQuote"
> 
> targetNamespace="http://example.com/stockquote/definitions"
>           xmlns:tns="http://example.com/stockquote/definitions"
>           xmlns:xsd1="http://example.com/stockquote/schemas"
>           xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
>           xmlns="http://schemas.xmlsoap.org/wsdl/">
> 
>    <import namespace="http://example.com/stockquote/schemas"
>            location="http://example.com/stockquote/stockquote.xsd"/>
> 
>     <message name="GetLastTradePriceInput">
>         <part name="body" element="xsd1:TradePriceRequest"/>
>     </message>
> 
>     <message name="GetLastTradePriceOutput">
>         <part name="body" element="xsd1:TradePrice"/>
>     </message>
> 
>     <portType name="StockQuotePortType">
>         <operation name="GetLastTradePrice">
>            <input message="tns:GetLastTradePriceInput"/>
>            <output message="tns:GetLastTradePriceOutput"/>
>         </operation>
>     </portType>
> </definitions>
> 
> Another example I found is (from
> http://www-128.ibm.com/developerworks/xml/library/ws-tip-imports.html):
> 
> <wsdl:types>
>     <xsd:schema targetNamespace="urn:listing2"
>                 xmlns:listing3="urn:listing3"
>                 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> 
>       <xsd:import namespace="urn:listing3" schemaLocation="listing3.xsd"/>
> 
>       <xsd:import namespace="http://www.w3.org/2001/XMLSchema"/>
>       <xsd:complexType name="Address">
>         <xsd:sequence>
>           <xsd:element name="streetNum" type="xsd:int"/>
>           <xsd:element name="streetName" type="xsd:string"/>
>           <xsd:element name="city" type="xsd:string"/>
>           <xsd:element name="state" type="xsd:string"/>
>           <xsd:element name="phone" type="listing3:Phone"/>
>         </xsd:sequence>
>       </xsd:complexType>
>     </xsd:schema>
>   </wsdl:types>
> 
> In the first example, the xsd file is being imported in the definition
> section, and I'm assuming is available throughout the rest of the wsdl after
> that.  In the second, the xsd is being imported in a schema within the types
> section and is therefore only available in that schema.  Is this correct?
> 
> I don't understand the significance/difference between the first example
> using "location" and the second using "schemaLocation".  I also don't
> understand how to reference the file's location.  Does it have to be made
> available on the internet as example 1 suggests, or is the xsd files
> co-located with wsdl good enough?
> 
> Any help is greatly appreciated.
> 
> Shelli
> 
>