Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML namespace of unprefixed child element where parent has xmlns:prefix declared

I'm aware of the default namespace in XML, e.g. declare xmlns="xxx" for an element, and this namespace will apply to all children without a prefix. My question is, if instead of xmlns="...", xmlns:pre="..." is declared in the element, are unprefixed child elements still associated with the namespace of the parent?

Here is an example:

<?xml version="1.0" ?>
<srv:tutorial xmlns:srv='http://www.w3resource.com/server-side-tutorial'>
    <name>php</name>
    <name>asp</name>
    <name>jsp</name>
</srv:tutorial>

What is the namespace of the three inner name elements?

like image 597
Brett Avatar asked Nov 04 '13 07:11

Brett


People also ask

What is namespace prefix in XML?

When using prefixes in XML, a namespace for the prefix must be defined. The namespace can be defined by an xmlns attribute in the start tag of an element. The namespace declaration has the following syntax. xmlns:prefix="URI".

What is xmlns attribute in XML?

The xmlns attribute specifies the xml namespace for a document. Note: The xmlns attribute is required in XHTML, invalid in HTML 4.01, and optional in HTML5.

What is xml namespace declare a default namespace?

When you use multiple namespaces in an XML document, you can define one namespace as the default namespace to create a cleaner looking document. The default namespace is declared in the root element and applies to all unqualified elements in the document. Default namespaces apply to elements only, not to attributes.

Why do we use xmlns in XML?

One of the primary motivations for defining an XML namespace is to avoid naming conflicts when using and re-using multiple vocabularies. XML Schema is used to create a vocabulary for an XML instance, and uses namespaces heavily.


1 Answers

All the three inner 'name' elements belong to the 'default' or 'empty' namespace, not the namespace prefixed with 'srv'.

like image 93
Alfred Xiao Avatar answered Oct 10 '22 23:10

Alfred Xiao