• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XML Namespace - Question

 
Ranch Hand
Posts: 577
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm doing mock tests from Whizlabs software. Here is the question I've come across and not sure of the answer they've given.

Q)Given the following XML declaration,
<x xmlns:n1="http://www.w3.org" xmlns:n2="http://www.w3.org" xmlns="http://www.w3.org">

Which of the following elements is valid with respect to attribute names?
A) <test a="1" a="2">
B) <test n1:a="1" n2:a="2" />
C) <test a=1 b=2 />
D) <test a="1" n1:a="2" />

Please give me the answer with reason.

Thanks and Regards,
Naren
 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Naren,

First the schema given is wrong because regarding to xml specification two prefixes not allowed to shared same schema. In schema n1 and n2 using the same namespace. But Same time default and one prefix allowed to use same namespace so there is no problem with default namespace declaration in schema.

In given option,

A Invalid
( due to duplicated attibute name)

C Invalid
(due to its missing " )

B) Invalid
(due to both a attribute belongs to same namespace)

If there is a answer, then that might be D.
 
Naren Chivukula
Ranch Hand
Posts: 577
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.

But as you said, the answer was D). Even in D) option, both a and n1:a refer to same namespace. In that case, D) would also be wrong!

Kind Regards,
Naren
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, D option is correct because default namespace does not apply to attributes.
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good Day,

It's probably a good idea to go through -

Namespaces in XML 1.0 (Second Edition), W3C Recommendation 16 August 2006 at http://www.w3.org/TR/REC-xml-names

Pretty short document.

The section which relates to this question is 'Using Qualified Names' at http://www.w3.org/TR/REC-xml-names/#ns-using

Regards,
Dan
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
xmlns="http://www.w3.org">

at first i thought d) option was wrong, because the default namespace was same as n1.
However, after chech the question again, i found the <x ...>'s scope has already finished.

hence, the a="1" dose not indicate the default namespase, it is a whatever.

am i right?
 
reply
    Bookmark Topic Watch Topic
  • New Topic