{
    "mode": "perldoc",
    "parameter": "Net::XMPP::Namespaces",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Net%3A%3AXMPP%3A%3ANamespaces/json",
    "generated": "2026-06-13T11:18:59Z",
    "synopsis": "Net::XMPP::Namespaces provides an depth look at how Net::XMPP handles namespacs, and how to add\nyour own custom ones. It also serves as the storage bin for all of the Namespace information\nNet::XMPP requires.",
    "sections": {
        "NAME": {
            "content": "Net::XMPP::Namespaces - In depth discussion on how namespaces are handled\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "Net::XMPP::Namespaces provides an depth look at how Net::XMPP handles namespacs, and how to add\nyour own custom ones. It also serves as the storage bin for all of the Namespace information\nNet::XMPP requires.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "XMPP as a protocol is very well defined. There are three main top level packets (message, iq,\nand presence). There is also a way to extend the protocol in a very clear and strucutred way,\nvia namespaces.\n\nTwo major ways that namespaces are used in Jabber is for making the <iq/> a generic wrapper, and\nas a way for adding data to any packet via a child tag <x/>. We will use <x/> to represent the\npacket, but in reality it could be any child tag: <foo/>, <data/>, <error/>, etc.\n\nThe Info/Query <iq/> packet uses namespaces to determine the type of information to access.\nUsually there is a <query/> tag in the <iq/> that represents the namespace, but in fact it can\nbe any tag. The definition of the Query portion, is the first tag that has a namespace.\n\n<iq type=\"get\"><query xmlns=\"...\"/></iq>\n\nor\n\n<iq type=\"get\"><foo xmlns=\"...\"/></iq>\n\nAfter that Query stanza can be any number of other stanzas (<x/> tags) you want to include. The\nQuery packet is represented and available by calling GetQuery() or GetChild(), and the other\nnamespaces are available by calling GetChild().\n\nThe X tag is just a way to piggy back data on other packets. Like embedding the timestamp for a\nmessage using jabber:x:delay, or signing you presence for encryption using jabber:x:signed.\n\nTo this end, Net::XMPP has sought to find a way to easily, and clearly define the functions\nneeded to access the XML for a namespace. We will go over the full docs, and then show two\nexamples of real namespaces so that you can see what we are talking about.\n",
            "subsections": [
                {
                    "name": "Overview",
                    "content": "To avoid a lot of nasty modules populating memory that are not used, and to avoid having to\nchange 15 modules when a minor change is introduced, the Net::XMPP modules have taken\nAUTOLOADing to the extreme. Namespaces.pm is nothing but a set of function calls that generates\na big hash of hashes. The hash is accessed by the Stanza.pm AUTOLOAD function to do something.\n(This will make sense, I promise.)\n\nBefore going on, I highly suggest you read a Perl book on AUTOLOAD and how it works. From this\npoint on I will assume that you understand it.\n\nWhen you create a Net::XMPP::IQ object and add a Query to it (NewChild) several things are\nhappening in the background. The argument to NewChild is the namespace you want to add.\n(custom-namespace)\n\nNow that you have a Query object to work with you will call the GetXXX functions, and SetXXX\nfunctions to set the data. There are no defined GetXXX and SetXXXX functions. You cannot look in\nthe Namespaces.pm file and find them. Instead you will find something like this:\n\n&addns(ns    => \"mynamespace\",\ntag   => \"mytag\",\nxpath => {\nJID       => { type=>'jid', path => '@jid' },\nUsername  => { path => 'username/text()' },\nTest      => { type => 'master' }\n}\n);\n\nWhen the GetUsername() function is called, the AUTOLOAD function looks in the Namespaces.pm hash\nfor a \"Username\" key. Based on the \"type\" of the field (scalar being the default) it will use\nthe \"path\" as an XPath to retrieve the data and call the XPathGet() method in Stanza.pm.\n\nConfused yet?\n"
                },
                {
                    "name": "Net::XMPP private namespaces",
                    "content": "Now this is where this starts to get a little sticky. When you see a namespace with netxmpp,\nor netjabber from Net::Jabber, at the beginning it is usually something custom to Net::XMPP\nand NOT part of the actual XMPP protocol.\n\nThere are some places where the structure of the XML allows for multiple children with the same\nname. The main places you will see this behavior is where you have multiple tags with the same\nname and those have children under them (jabber:iq:roster).\n\nIn jabber:iq:roster, the <item/> tag can be repeated multiple times, and is sort of like a\nmini-namespace in itself. To that end, we treat it like a separate namespace and defined a\nnetxmpp:iq:roster:item namespace to hold it. What happens is this, in my code I define that\nthe <item/>s tag is \"item\" and anything with that tag name is to create a new Net::XMPP::Stanza\nobject with the namespace netxmpp:iq:roster:item which then becomes a child of the\njabber:iq:roster Stanza object. Also, when you want to add a new item to a jabber:iq:roster\nproject you call NewQuery with the private namespace.\n\nI know this sounds complicated. And if after reading this entire document it is still\ncomplicated, email me, ask questions, and I will monitor it and adjust these docs to answer the\nquestions that people ask.\n\naddns()\nTo repeat, here is an example call to addns():\n\naddns(ns    => \"mynamespace\",\ntag   => \"mytag\",\nxpath => {\nJID       => { type=>'jid', path => '@jid' },\nUsername  => { path => 'username/text()' },\nTest      => { type => 'master' }\n}\n);\n\nns - This is the new namespace that you are trying to add.\n\ntag - This is the root tag to use for objects based on this namespace.\n\nxpath - The hash reference passed in the addns call to each name of entry tells Net::XMPP how\nto handle subsequent GetXXXX(), SetXXXX(), DefinedXXXX(), RemoveXXXX(), AddXXXX() calls. The\nbasic options you can pass in are:\n\ntype - This tells Stanza how to handle the call. The possible values are:\n\narray - The value to set and returned is an an array\nreference.  For example, <group/> in jabber:iq:roster.\n\nchild - This tells Stanza that it needs to look for the\nnetxmpp style namesapced children.  AddXXX() adds\na new child, and GetXXX() will return a new Stanza\nobject representing the packet.\n\nflag - This is for child elements that are tags by themselves:\n<foo/>.  Since the presence of the tag is what is\nimportant, and there is no cdata to store, we just call\nit a flag.\n\njid - The value is a Jabber ID.  GetXXX() will return a\nNet::XMPP::JID object unless you pass it \"jid\", then it\nreturns a string.\n\nmaster - The GetXXX() and SetXXX() calls return and take a\nhash representing all of the GetXXX() and SetXXX()\ncalls.  For example:\n\nSetTest(foo=>\"bar\",\nbar=>\"baz\");\n\nTranslates into:\n\nSetFoo(\"bar\");\nSetBar(\"baz\");\n\nGetTest() would return a hash containing what the\npacket contains:\n\n{ foo=>\"bar\",  bar=>\"baz\" }\n\nraw - This will stick whatever raw XML you specify directly\ninto the Stanza at the point where the path specifies.\n\nscalar - This will set and get a scalar value.  This is the\nmain workhorse as attributes and CDATA is represented\nby a scalar.  This is the default setting if you do\nnot provide one.\n\nspecial - The special type is unique in that instead of a\nstring \"special\", you actually give it an array:\n\n[ \"special\" , <subtype> ]\n\nThis allows Net::XMPP to be able to handle the\nSetXXXX() call in a special manner according to your\nchoosing.  Right now this is mainly used by\njabber:iq:time to automatically set the time info in\nthe correct format, and jabber:iq:version to set the\nmachine OS and add the Net::Jabber version to the\nreturn packet.  You will likely NOT need to use\nthis, but I wanted to mention it.\n\ntimestamp - If you call SetXXX() but do not pass it anything,\nor pass it \"\", then Net::XMPP will place a\ntimestamp in the xpath location.\n\npath - This is the XPath path to where the bit data lives.  The\ndifference.  Now, this is not full XPath due to the nature\nof how it gets used.  Instead of providing a rooted path\nall the way to the top, it's a relative path ignoring what\nthe parent is.  For example, if the \"tag\" you specified was\n\"foo\", and the path is \"bar/text()\", then the XPath will be\nrooted in the XML of the <foo/> packet.  It will set and get\nthe CDATA from:\n\n<foo><bar>xxxxx</bar></foo>\n\nFor a flag and a child type, just specify the child element.\nTake a look at the code in this file for more help on what\nthis means.  Also, read up on XPath if you don't already know\nwhat it is.\n\nchild - This is a hash reference that tells Net::XMPP how to handle\nadding and getting child objects.  The keys for the hash are\nas follows:\n\nns - the real or custom (netxmpp) namesapce to use for\nthis child packet.\n\nskipxmlns => 1 - this tells Net::XMPP not to add an\nxmlns='' into the XML for the child\nobject.\n\nspecifyname => 1 - allows you to call NewChild(\"ns\",\"tag\")\nand specify the tag to use for the child\nobject.  This, IMHO, is BAD XML\npractice.  You should always know what\nthe tag of the child is and use an\nattribute or CDATA to change the type\nof the stanza.  You do not want to use\nthis.\n\ntag - If you use specifyname, then this is the default tag\nto use.  You do not want to use this.\n\ncalls - Array reference telling Net::XMPP what functions to create\nfor this name.  For most of the types above you will get\nGet, Set, Defined, and Remove.  For child types you need to\ndecide how you API will look and specify them yourself:\n\n[\"Get\",\"Defined\"]\n[\"Add\"]\n[\"Get\",\"Add\",\"Defined\"]\n\nIt all depends on how you want your API to look.\n\nOnce more... The following:\n\n&addns(ns    => \"mynamespace\",\ntag   => \"mytag\",\nxpath => {\nJID       => { type=>'jid', path => '@jid' },\nUsername  => { path => 'username/text()' },\nTest      => { type => 'master' }\n}\n);\n\ngenerates the following API calls:\n\nGetJID()\nSetJID()\nDefinedJID()\nRemoveJID()\nGetUsername()\nSetUsername()\nDefinedUsername()\nRemoveUsername()\nGetTest()\nSetTest()\n"
                },
                {
                    "name": "Wrap Up",
                    "content": "Well. I hope that I have not scared you off from writing a custom namespace for you application\nand use Net::XMPP. Look in the Net::XMPP::Protocol manpage for an example on using the addns()\nfunction to register your custom namespace so that Net::XMPP can properly handle it.\n"
                }
            ]
        },
        "AUTHOR": {
            "content": "Originally authored by Ryan Eatmon.\n\nPreviously maintained by Eric Hacker.\n\nCurrently maintained by Darian Anthony Patrick.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "This module is free software, you can redistribute it and/or modify it under the LGPL 2.1.\n",
            "subsections": []
        }
    },
    "summary": "Net::XMPP::Namespaces - In depth discussion on how namespaces are handled",
    "flags": [],
    "examples": [],
    "see_also": []
}