Forums Register Login

XML Namespace - Question

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Hey, D option is correct because default namespace does not apply to attributes.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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?
I am a man of mystery. Mostly because of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 784 times.
Similar Threads
Confused with Xpath expression! Need Help.
Need help with some sample questions...
XML Schema
Unqualified elment - but still have prefix at the root
XyzWs exam question --doubt
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:36:07.