homepage Welcome to WebmasterWorld Guest from 184.73.40.21
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
namespaces
uri and wll formed
malhotra

5+ Year Member



 
Msg#: 3417720 posted 10:09 am on Aug 9, 2007 (gmt 0)

i am doing a exercise from a xml book. this question is on namespace and i am a newbie. it asks to identify the URI of the namespace or explain why element is not in namespace. is it wll formed?

<?xml version = "1.0" encoding = "UTF-8"?>
<root xmlns:a="AAA" >
<www xmlns:b="BBB" />
< #*$! xmlns:c="CCC">
<yyy xmlns:d="DDD"/>
<a:z />
<b:z />
<c:z />
<d:z />
<z />
</ #*$!>
</root>

not sure why #*$!> comes up, it should be x x x
and </ x x x.

 

cmarshall

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3417720 posted 3:23 pm on Aug 9, 2007 (gmt 0)

Welcome to WebmasterWorld!

XML Namespaces are a big pain in the patootie.

Here is a very useful (and verbose) XML namespace FAQ [rpbourret.com].

You need to define your namespace as a valid URI (not necessarily URL) format.

Here are a couple of examples:

<rootelem xmlns="http://www.example.com" xmlns:misc="http://www.example.com/misc">

or

<rootelem xmlns="urn:just-some-string">

Good luck.

malhotra

5+ Year Member



 
Msg#: 3417720 posted 3:51 pm on Aug 9, 2007 (gmt 0)

<?xml version = "1.0" encoding = "UTF-8"?>
<root xmlns:a="AAA" >
<www xmlns:b="BBB" />
< x xx xmlns:c="CCC">
<yyy xmlns:d="DDD"/>
<a:z />
<b:z />
<c:z />
<d:z />
<z />
</ x xx>
</root>

the question asks the five elements on lines 06 to 10 are local-name z. i need to identify the URI of the namespace of the element or why the element is not in a namespace.

my first thought was

line 6: <a:z /> is AAA
line 7: <b:z /> is BBB
line 8: <c:z /> is CCC
line 9: <d:z /> is DDD

but im not sure. any ideas please.

cheers

cmarshall

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3417720 posted 5:26 pm on Aug 9, 2007 (gmt 0)

<duh:thinkingCap>
I don't think that you will be able to do this:
line 9: <d:z /> is DDD

The reason is that it is not a child node of the element that declares the namespace URI:
<yyy xmlns:d="DDD"/>

I think that you need to actually need to declare the namespace URI in the element, thusly:
<z xmlns:d="DDD"/>

I'm also not sure that this is legal in XML:

< x xx xmlns:c="CCC">
.
.
.
</ x xx>

Spaces aren't allowed in element names.
</duh:thinkingcap>

malhotra

5+ Year Member



 
Msg#: 3417720 posted 10:18 am on Aug 10, 2007 (gmt 0)

the coding is fine, it is from an exercise. i didnt wrote it. ok ill ask a simple question first

what are the URI's of the code

cmarshall

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3417720 posted 10:44 am on Aug 10, 2007 (gmt 0)

Hmm...can you point me to the exercise? I'd like to have a gander at it myself. Maybe I need to learn a bit more about this stuff.

At first blush, I would look askance at any exercise that says that a space as the first character of an XML element name is OK [w3.org].

That namespace FAQ [rpbourret.com] is very, very good. I will be the first to admit that I am no namespace expert, but I haven't seen a namespace xmlns attribute [rpbourret.com] described in anything other than URI form [en.wikipedia.org]. But then, you learn something new every day, and I would be interested in learning a bit more about this. It sounds like XML is actually a bit more flexible than I'd thought.

malhotra

5+ Year Member



 
Msg#: 3417720 posted 11:07 am on Aug 10, 2007 (gmt 0)

the exercise is in a book, not on teh web. how do i send it to yoy

malhotra

5+ Year Member



 
Msg#: 3417720 posted 11:27 am on Aug 10, 2007 (gmt 0)

i put x x x because x xx doesnt appear on the forum, instead a < #*$! appears.

cmarshall

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3417720 posted 12:07 pm on Aug 10, 2007 (gmt 0)

Ah. Got it. No worries, then. Thanks for clearing it up. No need to send me the book :) My apologies for being snarky. I understand.

As the FAQ says [rpbourret.com], all xmlns content needs to be in URI [w3.org] form.

This means either a valid URL, or some other URI scheme [w3.org]. You can use the URN [w3.org] scheme, but the URN is supposed to be registered, sort of like a domain name. This is why the URL form is the most popular. It guarantees a unique namespace. Namespace declarations need to be globally unique.

Also, a namespace, as declared by the xmlns "attribute," applies to an element, and all its descendants. That's why declaring a namespace in <www will not apply to the subsequent <b:z element, as the <www element has been closed. The only namespaces that apply to the elements are the ones declared in <root and the <#*$! element (It turns into a stream of gibberish because WebmasterWorld has these rather annoying filters on its content, and I guess it thinks that you want to cuss).

Namespaces cannot be legally declared as "AAA" etc., because that is not valid URI form.

I sincerely hope that this helps you out.

[edited by: cmarshall at 12:33 pm (utc) on Aug. 10, 2007]

malhotra

5+ Year Member



 
Msg#: 3417720 posted 12:24 pm on Aug 10, 2007 (gmt 0)

thanks for the reply, helps understand better.
for arguments sake would line 6 AAA and line 8 CCC if it was well formed with proper URI. would 7 and 9 not be in a namespace because they are closed off.

what happens to the <z /> on line 10, does it have a URI and would it be the root URI.

cmarshall

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3417720 posted 12:39 pm on Aug 10, 2007 (gmt 0)

for arguments sake would line 6 AAA and line 8 CCC if it was well formed with proper URI. would 7 and 9 not be in a namespace because they are closed off.

That is correct. FAQ [rpbourret.com] says that the scope of a namespace is the element on which it is declared (using the xmlns declarator) and the descendants of the element.

what happens to the <z /> on line 10, does it have a URI and would it be the root URI.

That is in the default namespace. It either has no namespace, or, if you declare a default namespace [rpbourret.com], it is in that namespace.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved