{
    "mode": "perldoc",
    "parameter": "XML::NamespaceSupport",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ANamespaceSupport/json",
    "generated": "2026-06-10T17:24:25Z",
    "synopsis": "use XML::NamespaceSupport;\nmy $nsup = XML::NamespaceSupport->new;\n# add a new empty context\n$nsup->pushcontext;\n# declare a few prefixes\n$nsup->declareprefix($prefix1, $uri1);\n$nsup->declareprefix($prefix2, $uri2);\n# the same shorter\n$nsup->declareprefixes($prefix1 => $uri1, $prefix2 => $uri2);\n# get a single prefix for a URI (randomly)\n$prefix = $nsup->getprefix($uri);\n# get all prefixes for a URI (probably better)\n@prefixes = $nsup->getprefixes($uri);\n# get all prefixes in scope\n@prefixes = $nsup->getprefixes();\n# get all prefixes that were declared for the current scope\n@prefixes = $nsup->getdeclaredprefixes;\n# get a URI for a given prefix\n$uri = $nsup->geturi($prefix);\n# get info on a qname (java-ish way, it's a bit weird)\n($nsuri, $localname, $qname) = $nsup->processname($qname, $isattr);\n# the same, more perlish\n($nsuri, $prefix, $localname) = $nsup->processelementname($qname);\n($nsuri, $prefix, $localname) = $nsup->processattributename($qname);\n# remove the current context\n$nsup->popcontext;\n# reset the object for reuse in another document\n$nsup->reset;\n# a simple helper to process Clarkian Notation\nmy ($ns, $lname) = $nsup->parsejclarknotation('{http://foo}bar');\n# or (given that it doesn't care about the object\nmy ($ns, $lname) = XML::NamespaceSupport->parsejclarknotation('{http://foo}bar');",
    "sections": {
        "NAME": {
            "content": "XML::NamespaceSupport - a simple generic namespace support class\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 1.12\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use XML::NamespaceSupport;\nmy $nsup = XML::NamespaceSupport->new;\n\n# add a new empty context\n$nsup->pushcontext;\n# declare a few prefixes\n$nsup->declareprefix($prefix1, $uri1);\n$nsup->declareprefix($prefix2, $uri2);\n# the same shorter\n$nsup->declareprefixes($prefix1 => $uri1, $prefix2 => $uri2);\n\n# get a single prefix for a URI (randomly)\n$prefix = $nsup->getprefix($uri);\n# get all prefixes for a URI (probably better)\n@prefixes = $nsup->getprefixes($uri);\n# get all prefixes in scope\n@prefixes = $nsup->getprefixes();\n# get all prefixes that were declared for the current scope\n@prefixes = $nsup->getdeclaredprefixes;\n# get a URI for a given prefix\n$uri = $nsup->geturi($prefix);\n\n# get info on a qname (java-ish way, it's a bit weird)\n($nsuri, $localname, $qname) = $nsup->processname($qname, $isattr);\n# the same, more perlish\n($nsuri, $prefix, $localname) = $nsup->processelementname($qname);\n($nsuri, $prefix, $localname) = $nsup->processattributename($qname);\n\n# remove the current context\n$nsup->popcontext;\n\n# reset the object for reuse in another document\n$nsup->reset;\n\n# a simple helper to process Clarkian Notation\nmy ($ns, $lname) = $nsup->parsejclarknotation('{http://foo}bar');\n# or (given that it doesn't care about the object\nmy ($ns, $lname) = XML::NamespaceSupport->parsejclarknotation('{http://foo}bar');\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module offers a simple to process namespaced XML names (unames) from within any application\nthat may need them. It also helps maintain a prefix to namespace URI map, and provides a number\nof basic checks.\n\nThe model for this module is SAX2's NamespaceSupport class, readable at\nhttp://www.saxproject.org/namespaces.html It adds a few perlisations where we thought it\nappropriate.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "*   XML::NamespaceSupport->new(\\%options)\n\nA simple constructor.\n\nThe options are \"xmlns\", \"fatalerrors\", and \"autoprefix\"\n\nIf \"xmlns\" is turned on (it is off by default) the mapping from the xmlns prefix to the URI\ndefined for it in DOM level 2 is added to the list of predefined mappings (which normally\nonly contains the xml prefix mapping).\n\nIf \"fatalerrors\" is turned off (it is on by default) a number of validity errors will\nsimply be flagged as failures, instead of die()ing.\n\nIf \"autoprefix\" is turned on (it is off by default) when one provides a prefix of \"undef\"\nto \"declareprefix\" it will generate a random prefix mapped to that namespace. Otherwise an\nundef prefix will trigger a warning (you should probably know what you're doing if you turn\nthis option on).\n\nIf \"xmlns11\" us turned off, it becomes illegal to undeclare namespace prefixes. It is on by\ndefault. This behaviour is compliant with Namespaces in XML 1.1, turning it off reverts you\nto version 1.0.\n\n*   $nsup->pushcontext\n\nAdds a new empty context to the stack. You can then populate it with new prefixes defined at\nthis level.\n\n*   $nsup->popcontext\n\nRemoves the topmost context in the stack and reverts to the previous one. It will die() if\nyou try to pop more than you have pushed.\n\n*   $nsup->declareprefix($prefix, $uri)\n\nDeclares a mapping of $prefix to $uri, at the current level.\n\nNote that with \"autoprefix\" turned on, if you declare a prefix mapping in which $prefix is\nundef(), you will get an automatic prefix selected for you. If it is off you will get a\nwarning.\n\nThis is useful when you deal with code that hasn't kept prefixes around and need to\nreserialize the nodes. It also means that if you want to set the default namespace (i.e.\nwith an empty prefix) you must use the empty string instead of undef. This behaviour is\nconsistent with the SAX 2.0 specification.\n\n*   $nsup->declareprefixes(%prefixes2uris)\n\nDeclares a mapping of several prefixes to URIs, at the current level.\n\n*   $nsup->getprefix($uri)\n\nReturns a prefix given a URI. Note that as several prefixes may be mapped to the same URI,\nit returns an arbitrary one. It'll return undef on failure.\n\n*   $nsup->getprefixes($uri)\n\nReturns an array of prefixes given a URI. It'll return all the prefixes if the uri is undef.\n\n*   $nsup->getdeclaredprefixes\n\nReturns an array of all the prefixes that have been declared within this context, ie those\nthat were declared on the last element, not those that were declared above and are simply in\nscope.\n\nNote that at least one context must be added to the stack via \"pushcontext\" before this\nmethod can be called.\n\n*   $nsup->geturi($prefix)\n\nReturns a URI for a given prefix. Returns undef on failure.\n\n*   $nsup->processname($qname, $isattr)\n\nGiven a qualified name and a boolean indicating whether this is an attribute or another type\nof name (those are differently affected by default namespaces), it returns a namespace URI,\nlocal name, qualified name tuple. I know that that is a rather abnormal list to return, but\nit is so for compatibility with the Java spec. See below for more Perlish alternatives.\n\nIf the prefix is not declared, or if the name is not valid, it'll either die or return undef\ndepending on the current setting of \"fatalerrors\".\n\n*   $nsup->undeclareprefix($prefix);\n\nRemoves a namespace prefix from the current context. This function may be used in SAX's\nendprefixmapping when there is fear that a namespace declaration might be available\noutside their scope (which shouldn't normally happen, but you never know ;) ). This may be\nneeded in order to properly support Namespace 1.1.\n\n*   $nsup->processelementname($qname)\n\nGiven a qualified name, it returns a namespace URI, prefix, and local name tuple. This\nmethod applies to element names.\n\nIf the prefix is not declared, or if the name is not valid, it'll either die or return undef\ndepending on the current setting of \"fatalerrors\".\n\n*   $nsup->processattributename($qname)\n\nGiven a qualified name, it returns a namespace URI, prefix, and local name tuple. This\nmethod applies to attribute names.\n\nIf the prefix is not declared, or if the name is not valid, it'll either die or return undef\ndepending on the current setting of \"fatalerrors\".\n\n*   $nsup->reset\n\nResets the object so that it can be reused on another document.\n\nAll methods of the interface have an alias that is the name used in the original Java\nspecification. You can use either name interchangeably. Here is the mapping:\n\nJava name                 Perl name\n---------------------------------------------------\npushContext               pushcontext\npopContext                popcontext\ndeclarePrefix             declareprefix\ndeclarePrefixes           declareprefixes\ngetPrefix                 getprefix\ngetPrefixes               getprefixes\ngetDeclaredPrefixes       getdeclaredprefixes\ngetURI                    geturi\nprocessName               processname\nprocessElementName        processelementname\nprocessAttributeName      processattributename\nparseJClarkNotation       parsejclarknotation\nundeclarePrefix           undeclareprefix\n",
            "subsections": []
        },
        "VARIABLES": {
            "content": "Two global variables are made available to you. They used to be constants but simple scalars are\neasier to use in a number of contexts. They are not exported but can easily be accessed from any\npackage, or copied into it.\n\n*   $NSXMLNS\n\nThe namespace for xmlns prefixes, http://www.w3.org/2000/xmlns/.\n\n*   $NSXML\n\nThe namespace for xml prefixes, http://www.w3.org/XML/1998/namespace.\n",
            "subsections": []
        },
        "TODO": {
            "content": "- add more tests\n- optimise here and there\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "XML::Parser::PerlSAX\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "*   Robin Berjon <robin@knowscape.com>\n\n*   Chris Prather <chris@prather.org>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "This software is copyright (c) 2015 by Robin Berjon.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
            "subsections": []
        },
        "CONTRIBUTORS": {
            "content": "*   Chris Prather <cprather@hdpublishing.com>\n\n*   David Steinbrunner <dsteinbrunner@pobox.com>\n\n*   Paul Cochrane <paul@liekut.de>\n\n*   Paulo Custodio <pauloscustodio@gmail.com>\n",
            "subsections": []
        }
    },
    "summary": "XML::NamespaceSupport - A simple generic namespace processor",
    "flags": [],
    "examples": [],
    "see_also": []
}