2

A friend showed me the following XML doc and asked me some questions. I'd like to check them with you

For the XML document

<?xml version="1.0"?>
<product xmlns:m="urn:example.com:catalog">
    <m:productInfo>
        <detail xmlns="urn:example.com:products">
            <name>Hello World!</name>
        </detail>
    </m:productInfo>
</product>

What is the URI of the namespace to which the top level <product> element belongs?
What is the URI of the namespace to which the <productInfo> element belongs?

Thanks!

4
  • Will your "friend" also be awarding you marks based on how you answer these questions? Commented May 27, 2014 at 7:26
  • LOL. On the absence of reputation points I will be accepting money... or beer. Commented May 27, 2014 at 7:27
  • Here's another 2 - what namespace is detail in, and what namespace is element name in? Commented May 27, 2014 at 7:29
  • Do you want me to add those to the question? Commented May 27, 2014 at 7:30

1 Answer 1

2

product is in the no namespace (sometimes informally called global namespace), since, although it defines the namespace alias xmlns:m="urn:example.com:catalog", product itself is not in this namespace.

Product would only be in namespace urn:example.com:catalog if it was declared either:

<m:product xmlns:m="urn:example.com:catalog">

or if it reset the default namespace:

<product xmlns="urn:example.com:catalog">

productInfo IS in namespace urn:example.com:catalog, for the reason above.

Detail resets the default namespace:

<detail xmlns="urn:example.com:products">

Which means that detail, and sub-elements (such as name) are also in namespace urn:example.com:products

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.