what's the point of namespaces in xml?

dpopiz

Diamond Member
Jan 28, 2001
4,454
0
0
ok so let's take the w3c example:
what if you have

<table>
<tr>
<td>Cost</td>
<td>Tax</td>
<td>Shipping</td>
<td>Total</td>
</tr>
<tr>
<td>$500</td>
<td>$5</td>
<td>$20</td>
<td>$525</td>
</tr>
</table>

and

<table>
<look>
<wood>Oak</wood>
<finish>Caramel</finish>
</look>
<pricing>
<basecost>$400</basecost>
<msrp>$500</msrp>
</pricing>
</table>


ohnoes! !!! teh table element means 2 different things!
so they say just add a namespace.

but why not just make the two different table elements children of two different elements, such as:

<xhtml>
<table>
<tr>
<td>Cost</td>
<td>Tax</td>
<td>Shipping</td>
<td>Total</td>
</tr>
<tr>
<td>$500</td>
<td>$5</td>
<td>$20</td>
<td>$525</td>
</tr>
</table>
</xhtml>

and

<furniture>
<table>
<look>
<wood>Oak</wood>
<finish>Caramel</finish>
</look>
<pricing>
<basecost>$400</basecost>
<msrp>$500</msrp>
</pricing>
</table>
</furniture>
 

Modeps

Lifer
Oct 24, 2000
17,254
44
91
Honestly, it's easier and cleaner the W3Cs way... It looks like you could probably do it your way, but that seems to be more work.

edit: or maybe I just dont understand your question...

XML is only related to HTML in that it's tag based. There are no predefined tags in XML, you make up all your own stuffs.

edit2: yeah, I dont think I understand what the problem is. :)
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Because a <furniture> element might need to include data types from 2 different namespaces.

This happens all the time in SOAP, where you mix W3C types and (sometimes multiple) vendor types.
 

dpopiz

Diamond Member
Jan 28, 2001
4,454
0
0
Originally posted by: DaveSimmons
Because a <furniture> element might need to include data types from 2 different namespaces.

sorry, I don't understand what that means. could you explain?
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
This is a typical SOAP request from a PC client to a web server:

<SOAP-ENV:Body SOAP-ENV:encodingStyle="h ttp://schemas.xmlsoap.org/soap/encoding/">
<impl:getTemplateIDs><session xsi:type="impl:SessionVO"><currentLCID xsi:type="xsd:long">xxxx9</currentLCID><pass xsi:type="xsd:string">xxxxxx</pass><uniqueID xsi:type="xsd:string">turbo.xxxx.com-1xxxxx5-60</uniqueID>
<loginInsID xsi:type="xsd:string">3xxx9</loginInsID><institutionID xsi:type="xsd:long">3xxx9</institutionID><serverID xsi:type="xsd:long">3xxxx3</serverID>
<subject xsi:type="impl:SubjectVO"><consortiaID xsi:type="xsd:string">2xx.x7.x7.x7-1xxxx5-2xxxx1.designer1</consortiaID>
<lastName xsi:type="xsd:string">designer1</lastName><firstName xsi:type="xsd:string">designer1</firstName><personID xsi:type="xsd:long">20xxxx01</personID>
<remoteUserID xsi:type="xsd:string">2xxxxx1.Cxxxxxxxxxxxxxxx3</remoteUserID>
<lastLogoutTime xsi:type="xsd: dateTime">2xxx3-1x-2xxx2:13:38.0xxZ</lastLogoutTime>
<webctID xsi:type="xsd:string">designer1</webctID></subject><templateID xsi:type="xsd:long">0</templateID><domainID xsi:type="xsd:long">3xx80</domainID><loginInsName xsi:type="xsd:string">Institution Name</loginInsName><loginGlcID xsi:type="xsd:string">2xx.x7.x7.x7-1xxxxxx5-2xxxx1</loginGlcID><currentDomainID xsi:type="xsd:long">3xxxx0</currentDomainID><user xsi:type="xsd:string">2xx.x7.x7.x7-1xxxxxx5-2xxxxx1.designer1</user></session><learningContextID xsi:type="xsd:long">3xxx0</learningContextID></impl:getTemplateIDs></SOAP-ENV:Body></SOAP-ENV:Envelope>
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Every element in a SOAP message is typed, just like a variable in C++, and those types are usually namespace-qualified because you're mixing them from W3C and vendor types.

Some types may be basic types like strings, others are structs built from base types.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
This SOAP response from a server might be a little easier to read:

<soapenv:Envelope xmlns:soapenv="h ttp://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="h ttp://www.w3.org/2001/XMLSchema" xmlns:xsi="h ttp://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:getLearningContextIDsResponse soapenv:encodingStyle="h ttp://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="h ttp://www.webct.com/vista/sdk/contextv1p0">
<getLearningContextIDsReturn xsi:type="soapenc:Array" soapenc:arrayType="xsd:long[6]" xmlns:soapenc="h ttp://schemas.xmlsoap.org/soap/encoding/">
<item>37960</item>
<item>36959</item>
<item>37616</item>
<item>39153</item>
<item>37994</item>
<item>37884</item>
</getLearningContextIDsReturn>
</ns1:getLearningContextIDsResponse>
</soapenv:Body>
</soapenv:Envelope>
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
I don't understand the original complaint. Namespaces are used to help qualify elements to prevent ambiguity. If I define a <table> element as something that MUST have 4 leg elements, and you define it as something that MUST have a TBODY element, then I put it in some XML which could contain either type, there's no way to know if it is valid or even what the context is. Why would I want to separate my xml into two root nodes, which anyway isn't even possible...?