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

M

Martin Honnen

afshar said:
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.
 
J

Joe Kesselman

afshar said:
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/
 
Joined
May 15, 2010
Messages
5
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top