.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "XML::NamespaceSupport 3pm" .TH XML::NamespaceSupport 3pm "2022-06-28" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" XML::NamespaceSupport \- A simple generic namespace processor .SH "VERSION" .IX Header "VERSION" version 1.12 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use XML::NamespaceSupport; \& my $nsup = XML::NamespaceSupport\->new; \& \& # add a new empty context \& $nsup\->push_context; \& # declare a few prefixes \& $nsup\->declare_prefix($prefix1, $uri1); \& $nsup\->declare_prefix($prefix2, $uri2); \& # the same shorter \& $nsup\->declare_prefixes($prefix1 => $uri1, $prefix2 => $uri2); \& \& # get a single prefix for a URI (randomly) \& $prefix = $nsup\->get_prefix($uri); \& # get all prefixes for a URI (probably better) \& @prefixes = $nsup\->get_prefixes($uri); \& # get all prefixes in scope \& @prefixes = $nsup\->get_prefixes(); \& # get all prefixes that were declared for the current scope \& @prefixes = $nsup\->get_declared_prefixes; \& # get a URI for a given prefix \& $uri = $nsup\->get_uri($prefix); \& \& # get info on a qname (java\-ish way, it\*(Aqs a bit weird) \& ($ns_uri, $local_name, $qname) = $nsup\->process_name($qname, $is_attr); \& # the same, more perlish \& ($ns_uri, $prefix, $local_name) = $nsup\->process_element_name($qname); \& ($ns_uri, $prefix, $local_name) = $nsup\->process_attribute_name($qname); \& \& # remove the current context \& $nsup\->pop_context; \& \& # reset the object for reuse in another document \& $nsup\->reset; \& \& # a simple helper to process Clarkian Notation \& my ($ns, $lname) = $nsup\->parse_jclark_notation(\*(Aq{http://foo}bar\*(Aq); \& # or (given that it doesn\*(Aqt care about the object \& my ($ns, $lname) = XML::NamespaceSupport\->parse_jclark_notation(\*(Aq{http://foo}bar\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module offers a simple to process namespaced \s-1XML\s0 names (unames) from within any application that may need them. It also helps maintain a prefix to namespace \s-1URI\s0 map, and provides a number of basic checks. .PP The model for this module is \s-1SAX2\s0's NamespaceSupport class, readable at http://www.saxproject.org/namespaces.html It adds a few perlisations where we thought it appropriate. .SH "NAME" XML::NamespaceSupport \- a simple generic namespace support class .SH "METHODS" .IX Header "METHODS" .IP "\(bu" 4 XML::NamespaceSupport\->new(\e%options) .Sp A simple constructor. .Sp The options are \f(CW\*(C`xmlns\*(C'\fR, \f(CW\*(C`fatal_errors\*(C'\fR, and \f(CW\*(C`auto_prefix\*(C'\fR .Sp If \f(CW\*(C`xmlns\*(C'\fR is turned on (it is off by default) the mapping from the xmlns prefix to the \s-1URI\s0 defined for it in \s-1DOM\s0 level 2 is added to the list of predefined mappings (which normally only contains the xml prefix mapping). .Sp If \f(CW\*(C`fatal_errors\*(C'\fR is turned off (it is on by default) a number of validity errors will simply be flagged as failures, instead of \&\fBdie()\fRing. .Sp If \f(CW\*(C`auto_prefix\*(C'\fR is turned on (it is off by default) when one provides a prefix of \f(CW\*(C`undef\*(C'\fR to \f(CW\*(C`declare_prefix\*(C'\fR it will generate a random prefix mapped to that namespace. Otherwise an undef prefix will trigger a warning (you should probably know what you're doing if you turn this option on). .Sp If \f(CW\*(C`xmlns_11\*(C'\fR us turned off, it becomes illegal to undeclare namespace prefixes. It is on by default. This behaviour is compliant with Namespaces in \s-1XML 1.1,\s0 turning it off reverts you to version 1.0. .IP "\(bu" 4 \&\f(CW$nsup\fR\->push_context .Sp Adds a new empty context to the stack. You can then populate it with new prefixes defined at this level. .IP "\(bu" 4 \&\f(CW$nsup\fR\->pop_context .Sp Removes the topmost context in the stack and reverts to the previous one. It will \fBdie()\fR if you try to pop more than you have pushed. .IP "\(bu" 4 \&\f(CW$nsup\fR\->declare_prefix($prefix, \f(CW$uri\fR) .Sp Declares a mapping of \f(CW$prefix\fR to \f(CW$uri\fR, at the current level. .Sp Note that with \f(CW\*(C`auto_prefix\*(C'\fR turned on, if you declare a prefix mapping in which \f(CW$prefix\fR is \fBundef()\fR, you will get an automatic prefix selected for you. If it is off you will get a warning. .Sp This is useful when you deal with code that hasn't kept prefixes around and need to reserialize the nodes. It also means that if you want to set the default namespace (i.e. with an empty prefix) you must use the empty string instead of undef. This behaviour is consistent with the \&\s-1SAX 2.0\s0 specification. .IP "\(bu" 4 \&\f(CW$nsup\fR\->declare_prefixes(%prefixes2uris) .Sp Declares a mapping of several prefixes to URIs, at the current level. .IP "\(bu" 4 \&\f(CW$nsup\fR\->get_prefix($uri) .Sp Returns a prefix given a \s-1URI.\s0 Note that as several prefixes may be mapped to the same \s-1URI,\s0 it returns an arbitrary one. It'll return undef on failure. .IP "\(bu" 4 \&\f(CW$nsup\fR\->get_prefixes($uri) .Sp Returns an array of prefixes given a \s-1URI.\s0 It'll return all the prefixes if the uri is undef. .IP "\(bu" 4 \&\f(CW$nsup\fR\->get_declared_prefixes .Sp Returns an array of all the prefixes that have been declared within this context, ie those that were declared on the last element, not those that were declared above and are simply in scope. .Sp Note that at least one context must be added to the stack via \&\f(CW\*(C`push_context\*(C'\fR before this method can be called. .IP "\(bu" 4 \&\f(CW$nsup\fR\->get_uri($prefix) .Sp Returns a \s-1URI\s0 for a given prefix. Returns undef on failure. .IP "\(bu" 4 \&\f(CW$nsup\fR\->process_name($qname, \f(CW$is_attr\fR) .Sp Given a qualified name and a boolean indicating whether this is an attribute or another type of name (those are differently affected by default namespaces), it returns a namespace \s-1URI,\s0 local name, qualified name tuple. I know that that is a rather abnormal list to return, but it is so for compatibility with the Java spec. See below for more Perlish alternatives. .Sp If the prefix is not declared, or if the name is not valid, it'll either die or return undef depending on the current setting of \&\f(CW\*(C`fatal_errors\*(C'\fR. .IP "\(bu" 4 \&\f(CW$nsup\fR\->undeclare_prefix($prefix); .Sp Removes a namespace prefix from the current context. This function may be used in \s-1SAX\s0's end_prefix_mapping when there is fear that a namespace declaration might be available outside their scope (which shouldn't normally happen, but you never know ;) ). This may be needed in order to properly support Namespace 1.1. .IP "\(bu" 4 \&\f(CW$nsup\fR\->process_element_name($qname) .Sp Given a qualified name, it returns a namespace \s-1URI,\s0 prefix, and local name tuple. This method applies to element names. .Sp If the prefix is not declared, or if the name is not valid, it'll either die or return undef depending on the current setting of \&\f(CW\*(C`fatal_errors\*(C'\fR. .IP "\(bu" 4 \&\f(CW$nsup\fR\->process_attribute_name($qname) .Sp Given a qualified name, it returns a namespace \s-1URI,\s0 prefix, and local name tuple. This method applies to attribute names. .Sp If the prefix is not declared, or if the name is not valid, it'll either die or return undef depending on the current setting of \&\f(CW\*(C`fatal_errors\*(C'\fR. .IP "\(bu" 4 \&\f(CW$nsup\fR\->reset .Sp Resets the object so that it can be reused on another document. .PP All methods of the interface have an alias that is the name used in the original Java specification. You can use either name interchangeably. Here is the mapping: .PP .Vb 10 \& Java name Perl name \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& pushContext push_context \& popContext pop_context \& declarePrefix declare_prefix \& declarePrefixes declare_prefixes \& getPrefix get_prefix \& getPrefixes get_prefixes \& getDeclaredPrefixes get_declared_prefixes \& getURI get_uri \& processName process_name \& processElementName process_element_name \& processAttributeName process_attribute_name \& parseJClarkNotation parse_jclark_notation \& undeclarePrefix undeclare_prefix .Ve .SH "VARIABLES" .IX Header "VARIABLES" Two global variables are made available to you. They used to be constants but simple scalars are easier to use in a number of contexts. They are not exported but can easily be accessed from any package, or copied into it. .IP "\(bu" 4 \&\f(CW$NS_XMLNS\fR .Sp The namespace for xmlns prefixes, http://www.w3.org/2000/xmlns/. .IP "\(bu" 4 \&\f(CW$NS_XML\fR .Sp The namespace for xml prefixes, http://www.w3.org/XML/1998/namespace. .SH "TODO" .IX Header "TODO" .Vb 2 \& \- add more tests \& \- optimise here and there .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" XML::Parser::PerlSAX .SH "AUTHORS" .IX Header "AUTHORS" .IP "\(bu" 4 Robin Berjon .IP "\(bu" 4 Chris Prather .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2015 by Robin Berjon. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" .IP "\(bu" 4 Chris Prather .IP "\(bu" 4 David Steinbrunner .IP "\(bu" 4 Paul Cochrane .IP "\(bu" 4 Paulo Custodio