Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML Namespace - Question

 
Naren Chivukula
Ranch Hand
Posts: 577
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
 
Sundar Murthi
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • 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
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
 
Dhanasekaran Krishnasamy
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, D option is correct because default namespace does not apply to attributes.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • 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
 
Shouton Eulle
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic