What does xmlns:xsi and xmlns:xsd attributes mean?

Discussion in 'XML' started by afshar, May 11, 2009.

  1. afshar

    afshar Guest

    Hi there,

    What does xmlns:xsi and xmlns:xsd attributes mean in a root element
    like following?

    <Letter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">


    Many thanks,
    Afshar Mohebbi
    afshar, May 11, 2009
    #1
    1. Advertising

  2. afshar wrote:

    > What does xmlns:xsi and xmlns:xsd attributes mean in a root element
    > like following?
    >
    > <Letter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > xmlns:xsd="http://www.w3.org/2001/XMLSchema">


    xmlns:foo attributes declare namespaces so
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    declares the namespace http://www.w3.org/2001/XMLSchema-instance as
    bound to the prefix 'xsi' and
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    declares the namespace http://www.w3.org/2001/XMLSchema as bound to the
    prefix 'xsd'.
    That usually happens to use attributes like
    <bar xsi:type="xsd:integer">1</bar>
    in the XML.

    --

    Martin Honnen
    http://msmvps.com/blogs/martin_honnen/
    Martin Honnen, May 11, 2009
    #2
    1. Advertising

  3. afshar wrote:
    > What does xmlns:xsi and xmlns:xsd attributes mean in a root element
    > like following?
    >
    > <Letter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > xmlns:xsd="http://www.w3.org/2001/XMLSchema">


    Namespace declarations [1], presumably being declared here because the
    contents of the Letter may want to use elements or attributes in those
    namespaces.

    In this particular case, the namespaces being declared -- as the URIs
    imply -- are related to XML Schemas [2], possibly because the Letter's
    content may want to reference schema datatypes.

    [1] http://www.w3.org/TR/REC-xml-names/
    [2] http://www.w3.org/TR/xmlschema-0/
    Joe Kesselman, May 11, 2009
    #3
  4. afshar

    aljar

    Joined:
    May 15, 2010
    Messages:
    5
    xsd shema, xsi shema instance

    1. You typically use xsd namespace when defining an XMLShema to spec your xml.
    example:

    Code:
    <[B]xsd[/B]:schema xmlns:[B]xsd[/B]="uri of XMLSchema"
    xmlns="some uri"
    targetNamespace="some uri">
    
    <[B]xsd[/B]:element name="product" type="ProductType"/>
    <[B]xsd[/B]:element name="number" type="xsd:integer"/>
    
    <[B]xsd[/B]:complexType name="ProductType">
    <[B]xsd[/B]:sequence>
    <[B]xsd[/B]:element ref="number"/>
    <[B]xsd[/B]:element ref="size"/>
    </xsd:sequence>
    </xsd:complexType>
    ...
    </xsd:schema>
    2. You use xsi to specify a shema location. Assuming the above file is named prod.xsd,

    your prod.xml file may look like:
    Code:
    <prod:product xmlns:prod="uri of prod"
    xmlns:[B]xsi[/B]="uri of XMLSchema-instance"
    [B]xsi[/B]:schemaLocation=":uri of prod [B]prod.xsd[/B]">
    
    <prod:number>557</prod:number>
    <prod:size>10</prod:size>
    </prod:product>
    
    NOTE: the actual hyper links are not shown because I do not have enough privileges. they are repalced by the words some uri..., uri of ...
    aljar
    aljar, May 19, 2010
    #4
    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. Replies:
    8
    Views:
    9,030
    Martin Honnen
    Jun 9, 2005
  2. Replies:
    0
    Views:
    1,325
  3. Matthew Thorley

    ElementTree and xsi to xmlns conversion?

    Matthew Thorley, May 18, 2005, in forum: Python
    Replies:
    3
    Views:
    512
    Matthew Thorley
    May 19, 2005
  4. Craig

    ElementTree xmlns:xsi question

    Craig, Nov 29, 2006, in forum: Python
    Replies:
    1
    Views:
    518
    Fredrik Lundh
    Nov 29, 2006
  5. killy971
    Replies:
    2
    Views:
    640
    Johannes Koch
    Aug 15, 2008
Loading...

Share This Page