.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" 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::Namespace 3pm" .TH XML::Namespace 3pm "2021-01-03" "perl v5.32.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::Namespace \- Simple support for XML Namespaces .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& Example 1: using XML::Namespace objects \& \& use XML::Namespace; \& \& my $xsd = XML::Namespace\->new(\*(Aqhttp://www.w3.org/2001/XMLSchema#\*(Aq); \& \& # explicit access via the uri() method \& print $xsd\->uri(); # http://www.w3.org/2001/XMLSchema# \& print $xsd\->uri(\*(Aqinteger\*(Aq); # http://www.w3.org/2001/XMLSchema#integer \& \& # implicit access through AUTOLOAD method \& print $xsd\->integer; # http://www.w3.org/2001/XMLSchema#integer \& \& Example 2: importing XML::Namespace objects \& \& use XML::Namespace \& xsd => \*(Aqhttp://www.w3.org/2001/XMLSchema#\*(Aq, \& rdf => \*(Aqhttp://www.w3.org/1999/02/22\-rdf\-syntax\-ns#\*(Aq; \& \& # xsd and rdf are imported subroutines that return \& # XML::Namespace objects which can be used as above \& \& print xsd\->uri(\*(Aqinteger\*(Aq); # http://www.w3.org/2001/XMLSchema#integer \& print xsd\->integer; # http://www.w3.org/2001/XMLSchema#integer .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module implements a simple object for representing \s-1XML\s0 Namespaces in Perl. It provides little more than some syntactic sugar for your Perl programs, saving you the bother of typing lots of long-winded URIs. It was inspired by the Class::RDF::NS module distributed as part of Class::RDF. .SS "Using XML::Namespace Objects" .IX Subsection "Using XML::Namespace Objects" First load the XML::Namespace module. .PP .Vb 1 \& use XML::Namespace; .Ve .PP Then create an XML::Namespace object. .PP .Vb 1 \& my $xsd = XML::Namespace\->new(\*(Aqhttp://www.w3.org/2001/XMLSchema#\*(Aq); .Ve .PP Then use the \fBuri()\fR method to return an absolute \s-1URI\s0 from a relative path. .PP .Vb 1 \& print $xsd\->uri(\*(Aqinteger\*(Aq); # http://www.w3.org/2001/XMLSchema#integer .Ve .PP Alternately, use the \s-1AUTOLOAD\s0 method to map method calls to the \&\fBuri()\fR method. .PP .Vb 1 \& print $xsd\->integer; # http://www.w3.org/2001/XMLSchema#integer .Ve .SS "Importing XML::Namespace Objects" .IX Subsection "Importing XML::Namespace Objects" When you \f(CW\*(C`use\*(C'\fR the XML::Namespace module, you can specify a list of namespace definitions. .PP .Vb 3 \& use XML::Namespace \& xsd => \*(Aqhttp://www.w3.org/2001/XMLSchema#\*(Aq, \& rdf => \*(Aqhttp://www.w3.org/1999/02/22\-rdf\-syntax\-ns#\*(Aq; .Ve .PP This defines the \f(CW\*(C`xsd\*(C'\fR and \f(CW\*(C`rdf\*(C'\fR subroutines and exports them into the calling package. The subroutines simply return XML::Namespace objects initialised with the relevant namespace URIs. .PP .Vb 2 \& print xsd\->uri(\*(Aqinteger\*(Aq); # http://www.w3.org/2001/XMLSchema#integer \& print xsd\->integer; # http://www.w3.org/2001/XMLSchema#integer .Ve .SS "Overloaded Stringification Method" .IX Subsection "Overloaded Stringification Method" The XML::Namespace module overloads the stringification operator to return the namespace \s-1URI.\s0 .PP .Vb 1 \& my $xsd = XML::Namespace\->new(\*(Aqhttp://www.w3.org/2001/XMLSchema#\*(Aq); \& \& print $xsd; # http://www.w3.org/2001/XMLSchema# .Ve .SH "METHODS" .IX Header "METHODS" .SS "new($uri)" .IX Subsection "new($uri)" Constructor method which creates a new XML::Namespace object. It expects a single argument denoting the \s-1URI\s0 that the namespace is to represent. .PP .Vb 1 \& use XML::Namespace; \& \& my $xsd = XML::Namespace\->new(\*(Aqhttp://www.w3.org/2001/XMLSchema#\*(Aq); .Ve .SS "uri($path)" .IX Subsection "uri($path)" When called without arguments, this method returns the \s-1URI\s0 of the namespace object, as defined by the argument passed to the \fBnew()\fR constructor method. .PP .Vb 1 \& $xsd\->uri(); # http://www.w3.org/2001/XMLSchema# .Ve .PP An argument can be passed to indicate a path relative to the namespace \&\s-1URI.\s0 The method returns a simple concatenation of the namespace \s-1URI\s0 and the relative path argument. .PP .Vb 1 \& $xsd\->uri(\*(Aqinteger\*(Aq); # http://www.w3.org/2001/XMLSchema#integer .Ve .SS "import($name,$uri,$name,$uri,...)" .IX Subsection "import($name,$uri,$name,$uri,...)" This method is provided to work with the Exporter mechanism. It expects a list of \f(CW\*(C`($name, $uri)\*(C'\fR pairs as arguments. It creates XML::Namespace objects and accessor subroutines that are then exported to the caller's package. .PP Although not intended for manual invocation, there's nothing to stop you from doing it. .PP .Vb 1 \& use XML::Namespace; \& \& XML::Namespace\->import( xsd => \*(Aqhttp://www.w3.org/2001/XMLSchema#\*(Aq ); \& \& xsd()\->integer; # http://www.w3.org/2001/XMLSchema#integer .Ve .PP Note that the parentheses are required when accessing this subroutine. .PP .Vb 2 \& xsd()\->integer; # Good \& xsd\->integer; # Bad .Ve .PP Unlike those that are defined automatically by the Importer, Perl doesn't know anything about these subroutines at compile time. Without the parentheses, Perl will think you're trying to call the \&\f(CW\*(C`integer\*(C'\fR method on an unknown \f(CW\*(C`xsd\*(C'\fR package and you'll see an error like: .PP .Vb 1 \& Can\*(Aqt locate object method "integer" via package "xsd" .Ve .PP That's why it's better to define your namespaces when you load the XML::Namespace module. .PP .Vb 2 \& use XML::Namespace \& xsd => \*(Aqhttp://www.w3.org/2001/XMLSchema#\*(Aq; \& \& xsd\->integer; # Good .Ve .SS "\s-1AUTOLOAD\s0" .IX Subsection "AUTOLOAD" The module defines an \s-1AUTOLOAD\s0 method that maps all other method calls to the \fBuri()\fR method. Thus, the following return the same value. .PP .Vb 2 \& $xsd\->uri(\*(Aqinteger\*(Aq); # http://www.w3.org/2001/XMLSchema#integer \& $xsd\->integer; # http://www.w3.org/2001/XMLSchema#integer .Ve .SH "AUTHOR" .IX Header "AUTHOR" Andy Wardley .SH "VERSION" .IX Header "VERSION" This is version 0.02 of XML::Namespace. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (C) 2005 Andy Wardley. All Rights Reserved. .PP This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "SEE ALSO" .IX Header "SEE ALSO" The Class::RDF::NS module, distributed as part of Class::RDF, provided the inspiration for the module. XML::Namespace essentially does the same thing, albeit in a slightly different way. It's also available as a stand-alone module for use in places unrelated to \s-1RDF.\s0 .PP The XML::NamespaceFactory module also implements similar functionality to XML::Namespace, but instead uses the JClark notation (e.g. \*(L"{http://foo.org/ns/}title\*(R").