  | | | FOAF / XML Parser | FOAF / XML Parser 2004-03-16 - By Claus Wahlers
Back okay, here's a short tutorial on xml namespaces
first let me try to explain how xml namespaces work (the perfect explanation you'll get at http://www.w3.org/TR/REC-xml-names/ though)
namespaces in xml are used to group collections of names (here: xml elements, or "tags"). for example, the <a> element in xhtml might be treated differently from the <a> element in svg, so if you just name them both <a>, the parser/renderer wouldn't know which one belongs to what xml "module", that's why you have to add a namespace name, like for example <xhtml:a> and <svg:a>. packaging of classes in as2 works very similar: com.codeazur.blah.MyClass is different from com.codeazur.yadda.MyClass, although both classes have the same name.
lets take a look at a skeleton real world example:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xforms="http://www.w3.org/2002/xforms/cr"> <head> <xforms:model> <xforms:instance> <empty /> </xforms:instance> </xforms:model> </head> <body> </body> </html>
you don't need to understand xforms here, this is just an example.
let's examine the root tag, <html>
there are two strange attributes in there, both starting with "xmlns". they are called namespace declarations, and tell the parser "all elements in this document belong to the xhtml namespace, and all elements that have a "xforms:" in front belong to the xforms namespace".
namespace declarations may appear as a "xmlns" attribute (like in the first ns-declaration) *or* with an additional ":" plus a prefix name (like in the second ns-declaration"). the difference is that "xmlns" declares the *default namespace* (you can omit prefixes in your tags and write them just like you were used to), and "xmlns:xforms" declares a *prefix* (here "xforms"), so you would have to prefix your xforms-tags, like <xforms-model> in the above example.
the attribute value of a namespace declaration is a uri that unambiguously identifies the namespace.
namespace declarations are valid for the element they are declared upon and all of it's children, unless a child element redeclares a namespace (namespace declarations may occure on any element). if you declare your namespaces on the root tag, they are valid throughout the whole document.
now for Flash's XMLNode stuff:
- namespaceURI contains the url you declared as attribute value with your ns-declaration (http://www.w3.org/1999/xhtml or http://www.w3.org/2002/xforms/cr, depending on what namespace the element belongs to)
- localName contains the actual tag name (for the <xforms:instance> element, localName would be "instance"
- prefix contains the prefix (haha) (for the <xforms:instance> element, prefix would be "instance")
- getPrefixForNamespace(ns) returns the prefix for a given namespaceURI (getPrefixForNamespace("http://www.w3.org/2002/xforms/cr") on any element in the above example would return "xforms")
- getNamespaceForPrefix(pre) returns the namespaceURI for a given prefix (getNamespaceForPrefix("xforms") on any element in the above example would return "http://www.w3.org/2002/xforms/cr")
btw, also attributes can be namespaced. the flash xml parser does not support that natively though (just element names).
all without testing, straight out of my drug addicted brain, so feel free to correct me in case i'm wrong, inaccurate or just misguided ;) cheers, claus. c?deazur.com
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- Supported by Fig Leaf Software =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- Be sure to check the archives and the wiki: http://chattyfig.figleaf.com/ =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:107090 =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- To unsubscribe send a blank e-mail to: Normal Mode: flashcoders-unsubscribe@(protected) Digest Mode: flashcoders-digest-unsubscrive@(protected)
|
|
 |