The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> XML Programming
|
About xml namespaces
Discuss About xml namespaces in the XML Programming forum on Dev Shed. About xml namespaces XML Programming forum discussing XML and related technologies, including XUL and XSL. XML is a self-describing file format, designed for maximum compatibility between applications.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 10th, 2013, 06:23 PM
|
 |
A Change of Season
|
|
|
|
|
About xml namespaces
I understand that "namespaces" are a way of grouping elements and attributes under a common heading in order to differentiate them from a similarily named items.
I see this on top of documents quite often use the famouse w3.org url as the namespace:
Code:
<html xmlns="http://www.w3.org/1999/xhtml">
This namespace is a web page. It does not contain any rules or definitions of the namespace So does this mean a namespace could be "anything" as long as it's a unique string? It does not have to include any rules does it? The reason I ask is that I read: Quote: | Namespace identifier is a string of characters such as isbn, which identifies how the namespace specific string should be interpreted | How can it specify how a string should be interpreted if it is doesn't contain anything?
Thanks
Last edited by zxcvbnm : March 11th, 2013 at 12:33 AM.
|

March 10th, 2013, 07:45 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
Yes. Namespaces should be URIs (I've seen things that complain if they're not) but they don't have to be to some computer-readable specification. Human-readable is a good idea though.
As for your second question, it's too confusing, I can't tell what you're asking.
|

March 11th, 2013, 12:35 AM
|
 |
A Change of Season
|
|
|
|
Quote: | Originally Posted by requinix Yes. Namespaces should be URIs (I've seen things that complain if they're not) but they don't have to be to some computer-readable specification. Human-readable is a good idea though.
As for your second question, it's too confusing, I can't tell what you're asking. | Ok let's say it is a human readable string. How can a string contain rules or definitions? In other words, I can open a DTD and see all the rules and specifications but I don't understand how a string can contain rules!
I hope it's clear what I am asking 
|

March 11th, 2013, 12:49 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
It doesn't have to, that's what I'm saying. Neither the URI nor the document it's pointing to have to include rules or definitions or schema. It's more or less an arbitrary string. It is, however, a Good Thing To Do because then other people reading the XML can easily find out the schema without having to Google stuff or hunt down your documentation.
|

March 11th, 2013, 01:05 AM
|
 |
A Change of Season
|
|
|
|
Quote: | Originally Posted by requinix It doesn't have to, that's what I'm saying. Neither the URI nor the document it's pointing to have to include rules or definitions or schema. It's more or less an arbitrary string. It is, however, a Good Thing To Do because then other people reading the XML can easily find out the schema without having to Google stuff or hunt down your documentation. | I don't know if I am slow or these things are confusing for everyone!
|

March 11th, 2013, 04:24 AM
|
 |
A Change of Season
|
|
|
|
Requinix;
I am not gonna open a bew thread but I am going to ask a question here
1 - What is the difference between these 2 XMLs?
2 - What happens when I want applicationUsers element to use both namespaces?
3 - Why isnt there a prefix for the default name space?
Thank you
Code:
<hr:applicationUsers xmlns="http://www.webmoosh.com/namespaces/hr/entities"
xmlns:hr="http://www.webmoosh.com/namespaces/hr/config">
<user hr:firstname="Behnam" />
<user hr:firstname="John" />
</hr:applicationUsers>
And
Code:
<applicationUsers xmlns="http://www.webmoosh.com/namespaces/hr/entities"
xmlns:hr="http://www.webmoosh.com/namespaces/hr/config">
<user hr:firstname="Behnam" />
<user hr:firstname="John" />
</applicationUsers>
Last edited by zxcvbnm : March 11th, 2013 at 04:28 AM.
|

March 11th, 2013, 12:49 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
1. In the first the root node is in a different namespace than the <user>s below it. (In the second they're in the same one.)
2. You can't. A node or attribute can only belong in one namespace, though a node and its attributes don't all have to be in the same one (like with the <user>s).
3. Because it's easier that way?
|

March 11th, 2013, 06:37 PM
|
 |
A Change of Season
|
|
|
|
Thanks Requinix;
Is this valid? The reason I ask is that:
1 - There is no default name space. Both name spaces have prefix! Is it ok not to have a default name space?
2 - ApplicationUsers element does not have any namespace. Is it ok?
3 - Elements and attributes each have a seperate namespace assigned to them. For example the dial attributes under phone element has a different name space than phone element, still valid?
Code:
<applicationUsers xmlns:tr="http://www.webmoosh.com/namespaces/hr/entities"
xmlns:hr="http://www.webmoosh.com/namespaces/hr/config">
<user hr:firstname="Behnam" />
<address unit="5" />
<tr:phone hr:dial="5544098" />
</applicationUsers>
|

March 11th, 2013, 06:59 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
1. The default namespace always exists; if you don't define it yourself you get the default xmlns="". In your example <applicationUsers>, <user>, and <address> are in the default namespace.
2. Yes (see above) but I don't think that's what you want.
3. Yes.
|

March 13th, 2013, 05:06 PM
|
 |
A Change of Season
|
|
|
|
Requinx:
This is an over simplified xml:
Code:
<?xml version="1.0"?>
<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
And this is the Schema:
Code:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
1 - Why does the schema need name spaces? It makes sense that the xml simply looks at the schema without need to the namespaces in the schema. Would you please clarify why there is a need for name spaces in the schema itself?
2 - The <note> element could be anything right? For example <root>?
3 - Why defining xsi name space when it is not used in the xml at all?
4 - This schema is NOT a URI, right? Cause URI is a unique string which could not even exist. This schem (which is a namespace) is more than just a string. Clarify please.
Thanks
Last edited by zxcvbnm : March 13th, 2013 at 05:24 PM.
|

March 13th, 2013, 06:56 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
1. The schema needs the namespace corresponding to XML Schema itself, otherwise it's just plain XML.
2. Depends. In this case no because the associated schema only defines a "note" element. It also depends on what's reading the XML back and the purposes of the XML. Logically speaking the root could have been named anything but technically speaking the writers chose that name so that's what you have to use.
3. It does use it: the schemaLocation.
4. You mean the namespace? It certainly is a URI. The schemaLocation? That maps a namespace URI to an actual document (XML Schema) that can be used to validate the XML. So if a parser wanted to validate the XML it would load the "note.xsd" file and use it to validate stuff under the "http://www.w3schools.com" namespace.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|