Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between a 'local name' and 'qualified name' in a xml attribute

Tags:

java

xml

Can you please help me understand what is the difference between 'local name' and 'qualified name' in a xml attribute? From http://developer.android.com/reference/org/xml/sax/Attributes.html:

/** Look up an attribute's local name by index. */
abstract String getLocalName(int index)

/** Look up an attribute's XML qualified (prefixed) name by index. */    
abstract String getQName(int index)

In this example,

<anelement attr1="test" attr2="test2"> </anelement>

What will be the difference?

like image 380
michael Avatar asked Jun 21 '11 17:06

michael


People also ask

What is a qualified name in XML?

A QName, or qualified name, is the fully qualified name of an element, attribute, or identifier in an XML document. A QName concisely associates the URI of an XML namespace with the local name of an element, attribute, or identifier in that namespace.

What is local part in QName?

Generally speaking, localname is the local name, meaning inside the namespace. qname, or qualified name, is the full name (including namespace).

What is Xmlelement namespace?

XML namespaces provide a method for qualifying the names of XML elements and XML attributes in XML documents. A qualified name consists of a prefix and a local name, separated by a colon. The prefix functions only as a placeholder; it is mapped to a URI that specifies a namespace.


1 Answers

A local name is one which isn't qualified by a namespace. The fully qualified one includes the namespace, if any.

It's probably worth reading the W3C recommendation on XML names to get the full details.

Basically if you don't have xmlns anywhere in your XML file, you probably won't need to worry about namespaces. If you do have namespaces, you'll probably want to create a fully qualified name when checking for element names etc.

Note that attributes are generally less likely to use namespaces than elements, in my experience.

like image 156
Jon Skeet Avatar answered Oct 17 '22 08:10

Jon Skeet